Python3-私有属性

 1 class Person:
 2     __age = 20
 3 
 4     @classmethod
 5     def update_age(cls):
 6         cls.__age = 18
 7 
 8     @classmethod
 9     def show_age(cls):
10         print("修改后的年龄是:",cls.__age)
11 
12 Person.update_age()
13 Person.show_age()   # 改后的年龄是: 18

 

posted @ 2020-05-31 16:45  闹点小情绪q  阅读(88)  评论(0编辑  收藏  举报