-62 learning python class property additions and deletions of the investigation

                                                                             Class Properties

 

 

1. Class Properties

Class property, also known as static variables or static data. The class object data to which they pertain bound, not dependent on any instance of the class. 

 

2. CRUD

class zoo:
    country = 'china'
    def __init__(self,name,address,kind):
        self.name = name
        self.address = address
        self.kind = kind
    def monkey(self):
        print('this is monkey (%s)' %self.address)
    def tiger(self):
        print('this is tiger (%s)' %self.kind)
    def end(self):
        print(' Available for purchase to S% ' % the self.name) 
DWY = Zoo ( ' chinese \' Zoo S ' , ' Beijing ' , ' Others ' ) 

zoo.monkey (DWY) 
zoo.tiger (DWY) 
zoo.end (DWY) 

# attribute of the class deletions change search 

print (zoo.country)                   #   view the information 

zoo.country = ' US '                 # modification information 
print (zoo.country) 


zoo.snake = ' the this Snake iS '           # increase 
print(dwy.snake)


del zoo.country                 # 删除
del zoo.snake

print(zoo.__dict__)

 

operation result:

this is monkey (beijing)
this is tiger (others)
welcome to chinese's zoo
china
US
this is snake
{'__module__': '__main__', '__init__': <function zoo.__init__ at 0x7fb30efb8d90>, 'monkey': <function zoo.monkey at 0x7fb30efb8f28>, 'tiger': <function zoo.tiger at 0x7fb30efc9048>, 'end': <function zoo.end at 0x7fb30efc9378>, '__dict__': <attribute '__dict__' of 'zoo' objects>, '__weakref__': <attribute '__weakref__' of 'zoo' objects>, '__doc__': None}

Process finished with exit code 0

 

Guess you like

Origin www.cnblogs.com/liujinjing521/p/11457902.html