Here something you can look at.
class testClass(object):
def __init__(self):
self.my_dict = {}
def uppdate(self,key, value):
self.my_dict[key] = value
def remove(self,del_key):
del self.my_dict[del_key]
def show_data(self):
print self.my_dict
if __name__ == '__main__':
test = testClass()
test.uppdate('a', 1)
test.uppdate('b', 2)
test.uppdate('c', 3)
test.remove('c')
test.show_data() #{'a': 1, 'b': 2}
Something to think off is that a class uses dicitonary as a internal storage.
Example.
class Server(object):
'''python constructor'''
def __init__(self, server_name, port):
self.server_name = server_name
self.port = port
server_1 = Server('master_100', 1234)
server_2 = Server('blob_500', 9999)
#if we print the internal working of the class storage of variables
print server_1.__dict__
print server_2.__dict__
'''Out-->
{'port': 1234, 'server_name': 'master_100'}
{'port': 9999, 'server_name': 'blob_500'}
'''
#So it work like a dictionary if we call server_name(key)
#We are getting the value.
print server_1.server_name
#--> master_100
print server_2.port
#--> 9999