Dictionary and Attribute Operators

Operations on Dictionaries

     x = d[k]           Lookup by key
     d[k] = x           Assignment
     del d[k]           Delete an item
     len(d)             Number of items in dictionary 
  • Examples
     a = d['name']
     d['email'] = "beazley@cs"
     del d['phone']

Attribute Operator (.)

  • The dot (.) operator is used to access the attributes of an object
     foo.x = 3
     print foo.y
     a = foo.bar(3,4,5)
     a = foo.bar(3,4,5).spam 
  • Usually this corresponds to a dictionary lookup on __dict__
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 59
July 17, 2000, beazley@cs.uchicago.edu
>>>