Python 3 - 基本类属性和方法

attributes.py

class Point:
    pass

p1 = Point()
p2 = Point()

p1.x = 5
p1.y = 4

p2.x = 3
p2.y = 6

print(p1.x, p1.y)
print(p2.x, p2.y)

first_method.py

class Point:
    def reset(self):
        self.x = 0
        self.y = 0

p = Point()
p.reset()
print(p.x, p.y)

转载于:https://www.cnblogs.com/davidgu/p/4744835.html

猜你喜欢

转载自blog.csdn.net/weixin_34240520/article/details/93802993