[Tutor] appending/updating values dict key value pairs

Alan Gauld alan.gauld at btinternet.com
Sat Jun 22 23:16:43 CEST 2013


On 22/06/13 17:56, Sivaram Neelakantan wrote:

>>>> list.append(b.get('a'),'c')


Lets look at what this is doing in simplistic terms.

'list' is the class and 'append' is a method of the class.
When we call a method via the class we have to provide the 'self' 
argument explicitly so in this case self is

b.get('a')

which is the result of getting the value associated with the key 'a'; in b.

or put another way it is b['a']

so we can simplify a little to

list.append(b['a'], 'c')

But we normally call methods via the object instance rather than the 
class so simplifying this further we get:

b['a'].append('c')

Which is how we would normally do it.

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list