default behavior

wheres pythonmonks wherespythonmonks at gmail.com
Thu Jul 29 14:12:09 EDT 2010


Why is the default value of an int zero?

>>> x = int
>>> print x
<type 'int'>
>>> x()
0
>>>

How do I build an "int1" type that has a default value of 1?
[Hopefully no speed penalty.]
I am thinking about applications with collections.defaultdict.
What if I want to make a defaultdict of defaultdicts of lists?  [I
guess my Perl background is showing -- I miss auto-vivification.]

W



More information about the Python-list mailing list