Special class members python-

 

First, members of the modifier

    There are members of the 
    private members of 
    
    class Foo:
         DEF  __init__ (Self, name): 
            self.name = name
             # self.age = Age 
            Self. __Age = Age # private, can not access external 
     DEF Show (Self): 
        return Self .__ Age
obj
= Foo ( ' Zichuan ' , 21 is ) Print (obj.name) # obj.age Print (obj. __age) # private
------------------------ -----------------------------
class Foo:
  V = '123'
  DEF the __init __ (Self):
    pass
  def show(self):
    return Foo.__v
  @staticmethod  #静态方法
  def stat(self):
    return Foo.__v
#print(Foo.__v)
#ret = Foo().show()
#print(ret)

ret = Foo.stat()
print(ret)
------------------------------------------

class Foo:
  def __fl(self):
    return 123
  def f2(self):
    r = self.__f1()
    return r
obj = Foo()
ret = obj.f2()
print(ret)
----------------------------------------------
class F:
  def __init__(self):
    self.ge = 123
    seld.__game = 123

class s(F):
  def __init__(self,name):
    self.name = name
    self.__age = 21
     super(s,self).__init__()
  def show(self):
    print(self.name)
    print(self.__age)
    print(self.ge)
    #print(self.__game)
s = s('zichuan')
s.show()

 

Second, the members of the special

class Foo:
    def __init__(self):
        print('init')
    
    def __call__(self,'args,**kwargs):
       print('call') 
    
obj = Foo()
obj()
#Foo()()

-------------------------------------------

 

Third, starting the metaclass that, like  

a.python together everything is an object 
b. 
    class Foo:
         Pass 

    obj = Foo ()
     # obj is an object, Foo class 
    # Foo class is an object, type object

 

Guess you like

Origin www.cnblogs.com/zi-Chuan/p/11260490.html