What are “named tuples” in Python?

前端 未结 11 2093
名媛妹妹
名媛妹妹 2020-11-22 06:58

Reading the changes in Python 3.1, I found something... unexpected:

The sys.version_info tuple is now a named tuple:

11条回答
  •  遇见更好的自我
    2020-11-22 07:27

    named tuples allow backward compatibility with code that checks for the version like this

    >>> sys.version_info[0:2]
    (3, 1)
    

    while allowing future code to be more explicit by using this syntax

    >>> sys.version_info.major
    3
    >>> sys.version_info.minor
    1
    

提交回复
热议问题