The study notes package python

class Room: 
DEF the __init __ (Self, name, length, width):
Self .__ name = name
Self .__ length = length
Self .__ width = width
DEF get_name (Self):
return Self .__ name
DEF set_name (Self, newName):
IF type (newName) and newName.isdigit iS str () == False:
Self .__ name = newName
the else:
Print ( 'illegal name')
DEF Area (Self):
return length * Self Self .__ .__ width

jin = Room ( ' gold boss ', 2,1)
Print (jin.area ())
jin.set_name (' 2 ')
Print (jin.get_name ())

# assumption that private property can be a subclass of the parent class to call it
class Foo:
__key =' 123 '# _Foo__key

class Son (Foo):
Print (Foo .__ Key) # _Son__key


# will use proprietary concept de Scene
# 1 Hidden attribute from a class do not want external calls
# 2. I want to protect this property, do not want the property to be changed arbitrarily
# 3. I want to protect the property, not inherited by subclasses



Guess you like

Origin www.cnblogs.com/CoolClare/p/11005538.html