Integers have docstring for int()

Andrew Durdin adurdin at
Wed Aug 11 14:08:28 CEST 2004

I accidentally discovered that all the basic types in Python have
docstrings that describe the functions to create them. For integers,
you get:

>>> (1).__doc__
'int(x[, base]) -> integer\n\nConvert a string or number to an integer, if possi
ble.  A floating point\nargument will be truncated towards zero (this does not i
nclude a string\nrepresentation of a floating point number!)  When converting a
string, use\nthe optional base.  It is an error to supply a base when converting
 a\nnon-string. If the argument is outside the integer range a long object\nwill
 be returned instead.'

Similarly, (1.0).__doc__ gives the docstring for float(), "".__doc__
gives it for str(), [].__doc__ gives it for list(), and {}.__doc__
gives it for dict().

This seems a little unexpected to me; is there any particular reason
for this behaviour?

More information about the Python-list mailing list