[Tutor] Question about dictionary method get()
alan.gauld at blueyonder.co.uk
Mon Jun 28 18:37:13 EDT 2004
> Uh, oh. I just now tried print D.get("v") and did get
> Then why not with the plain D.get("v") ? Maybe I've found the
> source of my confusion?
Python has two methods __str__ and __repr__ that convert objects
When you evaluate an object
You are calling __repr__ on x
When you print an object
>>> print x
You are calling the __str__ method of x.
Often str and repr produce the same result but not always.
None is an example of a difference.
Notice too the difference when dealing with strings....
More information about the Tutor