首页 > 代码库 > python3 封装

python3 封装

技术分享
 1 class Foo:
 2     __x=1
 3     def __init__(self,name,age,gender,money):
 4         self.__name=name
 5         self.__age=age
 6         self.__gender=gender
 7         self.__money=money
 8     def tell_info(self):
 9         print(self.__name)
10         print(self.__age)
11         print(self.__gender)
12         print(self.__money)
13 
14 f1=Foo(egon,19,man,1888)
15 f1.tell_info()
16 
17 class A:
18     def __spam(self): #_A__spam
19         print(A.spam)
20 
21     def test(self):
22         print(A.test)
23         self.__spam() #self._A__spam
24 class B(A):
25     def __spam(self): #_B__spam
26         print(B.spam)
27 
28 b1=B()
29 b1.test()
View Code
>>打印
egon 19 man 1888 A.test A.spam

  

python3 封装