Answers for "struct trong python"

0

struct trong python

from collections import namedtuple

Something = namedtuple("Something", ["x", "y"])
p1 = Point(1, 2)
print(p1)
# gọi attribute
print(p1.x, p1.y)
# gọi theo chỉ số
print(p1[0], p1[1])

# nếu có ý định gán thì error ngay lập tức
p1.x = 2  # lỗi AttributeError: can't set attribute
Posted by: Guest on September-15-2021

Python Answers by Framework

Browse Popular Code Answers by Language