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(, y=)
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(, y=)
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(, y=)
print(p)
上一篇:【代码笔记】iOS-圆角矩形


下一篇:八款强大的jQuery图片滑块动画插件