标签:style int pwd turn 方法 静态属性 key 私有 person
120
1 #封装 2 3 class Person: 4 def __init__(self,name,passwd): 5 self.name=name 6 self.__passwd=passwd 7 8 def get_pwd(self): 9 return self.__passwd 10 11 Jack=Person("Jack","abc123") 12 13 print(Jack._Person__passwd) 14 print(Jack.get_pwd())
F:\pythonkaifa\python_learning\20191>python 封装.py abc123 abc123
1 #封装 2 3 class Person: 4 #静态属性也可以私有 5 __key=123 6 def __init__(self,name,passwd): 7 self.name=name 8 self.__passwd=passwd 9 #私有方法 10 def __get_pwd(self): 11 print(self.__dict__) 12 return self.__passwd 13 14 def login(self): 15 self.__get_pwd() 16 17 Jack=Person("Jack","abc123") 18 19 #print(Jack._Person__passwd) 20 #print(Jack.get_pwd()) 21 Jack.login()
标签:style int pwd turn 方法 静态属性 key 私有 person
原文地址:https://www.cnblogs.com/Mengchangxin/p/10336291.html