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)

 

posted @ 2015-08-20 12:52  Master HaKu  阅读(456)  评论(0编辑  收藏  举报