Python 命名元组

Posted on 2018-12-29 17:07  缥缈映苍穹  阅读(133)  评论(0)    收藏  举报
from collections import namedtuple

# 类
p = namedtuple("Point", ["x", "y","z"])
# 对象
p1 = p(10, 20,30)
print(p1)

print(p1.x)
print(p1.y)

car = namedtuple("Car", ["pai", "color", "pailiang"])
c = car("京C-10000", "绿色", "1.8T")
print(c)

import time
print(time.localtime())

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y
Point(10,20)