菜单

Private private property of Python

2017年11月22日 - PHPer

In Python, the variables outside the class method are called attributes, and the variables within the class method are called fields. Their private public access methods are similar.

 

Code is as follows

ClassC:

__name= “private property”

 

Deffunc (self):

Print (C.__name)

 

Classsub_C (C):

Definfo (self):

Print (C.__name) # private fields in the derived class can’t access the parent class

Obj=C ()

Obj.func ()

Obj=sub_C ()

Obj.info ()

 

Method and attribute access are similar in the above way, that is, the private member can only be used within the class

发表评论

电子邮件地址不会被公开。