class Site: __wocao = 123 # Private property wocao = 456 # Public attribute def __init__(self, name, url): self.name = name # public self.__url = url # private def who(self): print('name : ', self.name) print('url : ', self.__url) def __foo(self): # Private method print(' This is the private method ') def __xxoo(self): print(" This is a xxoo Private methods of !") def foo(self): # Public methods print(' It's the public way ') self.__foo() self.__xxoo() print(" Private properties of class , Can only be called inside a class :",__wocao) x = Site(' Dean Technology ', 'https://myit.icu') print(" Call the public property of the class :",x.wocao) # Invokes the properties of the class # print(x.__wocao) # Private properties of a class cannot be called x.who() # Normal output x.foo() # Normal output
Private properties of class , Can only be called inside a class : 123 Call the public property of the class : 456 name : Dean Technology url : https://myit.icu It's the public way This is the private method This is a xxoo Private methods of !
Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .