Home >Backend Development >Python Tutorial >Briefly understand python private and public attributes
In python, variables outside methods within a class are called attributes, and variables within methods within a class are called fields. Their private and public access methods are similar.
class C: __name="私有属性" def func(self): print(C.__name) class sub_C(C): def info(self): print(C.__name)#派生类中不可以访问父类的私有字段 obj=C() obj.func() obj=sub_C() obj.info()
The access to methods and properties is similar to the above method, that is: private members can only be used inside the class
The above is the detailed content of Briefly understand python private and public attributes. For more information, please follow other related articles on the PHP Chinese website!