from collections import namedtuple 使用

Posted zhangbo2008

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了from collections import namedtuple 使用相关的知识,希望对你有一定的参考价值。

from collections import namedtuple


Point = namedtuple(Point, [x, y])#本质就是等价于 class Point():
                 #                                           def __init__(self,x,y):
                 #                                                    self.x=x
                 #                                                    self.y=y
p = Point(11, y=22) 
print(p)

 这里面起名是有点玄学

技术分享图片
from collections import namedtuple


Point = namedtuple(dsafdsf, [x, y])#本质就是等价于 class Point():
                 #                                           def __init__(self,x,y):
                 #                                                    self.x=x
                 #                                                    self.y=y
                 #得到的类就叫Point来引用即可
p = Point(11, y=22) 
print(p)
View Code

 

以上是关于from collections import namedtuple 使用的主要内容,如果未能解决你的问题,请参考以下文章