self.data != self.update
Here self.data is an instance variable which is a dictionary object. Dictionary object has update method. So when you call self.data.update(), it calls the method inside the dictionary:
>>> help(dict.update)
Help on method_descriptor:
update(...)
D.update(E, **F) -> None. Update D from dict/iterable E and F.
If E has a .keys() method, does: for k in E: D[k] = E[k]
If E lacks .keys() method, does: for (k, v) in E: D[k] = v
In either case, this is followed by: for k in F: D[k] = F[k]
>>>
And self.update is an instance method of class Udict:
So lets re-write your code a little bit:
>>> class Udict:
... def __init__(self):
... self.data = dict()
... def update(self, dic=None):
... if dic:
... self.data.update(dic)
... return self.data
...
>>> d = {1:'one', 2:'two'}
>>> g = Udict()
>>> g.update(d)
{1: 'one', 2: 'two'}
For better practice, please don't call any method from init(), please use init() only for initializing attributes, so in your case you can even initialised dic from the argument like:
>>> class Udict:
... def __init__(self, dic=None):
... self.data = dict()
... if dic:
self.data.update(dic)
Please let me know if that helps.