__str__ effect
Originally the Print class object is the printed memory address
But after adding the __str__ parameter to the class
Re-printing This class object is showing return in __str__
__del__ effect
Executes when an instantiated object is freed in memory
Item operation
Operation of item by set get Del
The ultimate goal is to manipulate the variables inside the class like a dictionary
When this is done, different item is triggered
Class A:
def __init__ (self,name):
Self.name=name
def __getitem__ (self, item):
Print (' Get ')
def __setitem__ (self, Key, value):
Print (' Set ')
def __delitem__ (self, key):
Print (' del ')
Jg=a (' La ')
jg[' name ']=666
jg[' name ']
Del jg[' name ']
The ultimate goal is to manipulate the variables inside the class like a dictionary
Class A:
def __init__ (self,name):
Self.name=name
def __getitem__ (self, item):
Print (Self.name)
def __setitem__ (self, Key, value):
Self.name=value
def __delitem__ (self, key):
Del Self.name
Jg=a (' La ')
jg[' name ']=666
jg[' name ']
Del jg[' name ']
jg[' name ']
Python_day8 Object-oriented common supplement