且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

类型名称在namedtuple中的相关性

更新时间:2023-01-02 21:33:41

namedtuple()tuple子类的工厂函数.在这里,'whatsmypurpose'是类型名称.创建命名元组时,将在内部创建具有此名称(whatsmypurpose)的类.

namedtuple() is a factory function for tuple subclasses. Here, 'whatsmypurpose'is the type name. When you create a named tuple, a class with this name (whatsmypurpose) gets created internally.

您可以通过使用以下详细参数来注意到这一点:

You can notice this by using the verbose argument like:

Point=namedtuple('whatsmypurpose',['x','y'], verbose=True)

您也可以尝试type(p)进行验证.

Also you can try type(p) to verify this.