Twenty-eight chapters python basis: Object-Oriented commonly used functions

Object-oriented common functions

Whether #issubclass () detecting a class is a subclass of another class
# the Person class ():
# Eye = "2"
# DEF RUN (Self):
# Print ( 'running humans')
# Human class (the Person):
Pass #
# Human REN = ()
# RES = issubclass (Human, the Person)
# Print (RES)
#isinstance (): detecting whether an object is an instance of the specified class
# the Person class ():
# Eye = "2"
# RUN DEF (Self):
# Print ( 'humans running')
# REN = the Person ()
# RES = isinstance (REN, the Person)
# Print (RES)

#hasattr (): detection class / object contains the name of the designated members
the Person class # ():
# Eye = "2"
# DEF RUN (Self):
# Print ( 'humans running')
# REN = the Person ()
# RES = hasattr (REN, 'Eye'
# print(res)

#getattr (): Gets the value of the members of the class / object
# class the Person ():
# Eye = "2"
# DEF RUN (Self):
# Print ( 'humans running')
# REN = the Person ()
# member name exists it returns the corresponding value
# res = getattr (ren, 'female')
# Print (RES)
# member name does not exist return the default value
# res = getattr (ren, 'female')
# Print (RES)

#setattr (): a member of the class attribute value / target
# the Person class ():
# Eye = "2"
# DEF RUN (Self):
# Print ( 'running humans')
# = REN the Person ( )
# # member name does not exist, add
# setattr (ren, 'name'small four')
# Print (ren.name)
#
# # member name exists on the amendment
# setattr (ren, 'eye'. 4 ')
# Print (REN.

Eye) #delattr (): Delete a member of the class / object
# class the Person ():
# Eye = "2"
# DEF RUN (Self):
# Print ( 'humans running')
# REN = the Person ()
# Print (the Person .__ dict__)
# delattr (the Person, 'Eye')
# Print (the Person .__ dict__)

# dir (): list of all members get an object that can be accessed
# class the Person ():
# Eye = "2"
# DEF RUN (Self):
# Print ( 'humans running')
# REN = the Person ()
# RES = dir (REN)
Print # (RES)

Property (): the role later say: a function operation setting descriptor

Guess you like

Origin www.cnblogs.com/szc-boke/p/11285666.html