Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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
Source by daynhauhoc.com #
 
PREVIOUS NEXT
Tagged: #struct #trong #python
ADD COMMENT
Topic
Name
8+8 =