What are “named tuples” in Python?

前端 未结 11 2090
名媛妹妹
名媛妹妹 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:37

    In Python inside there is a good use of container called a named tuple, it can be used to create a definition of class and has all the features of the original tuple.

    Using named tuple will be directly applied to the default class template to generate a simple class, this method allows a lot of code to improve readability and it is also very convenient when defining a class.

提交回复
热议问题