Integers have docstring for int()

Gandalf gandalf at geochemsource.com
Wed Aug 11 09:46:02 EDT 2004


>
>
>I accidentally discovered that all the basic types in Python have
>docstrings that describe the functions to create them. For integers,
>you get:
>
Acually, they are not functions. They are built-in types. For example, 
try  this:

Python 2.3.3 (#1, Mar  8 2004, 14:26:02)
[GCC 3.3.3 [FreeBSD] 20031106] on freebsd5
Type "help", "copyright", "credits" or "license" for more information.
 >>> int
<type 'int'>
 >>>

It is not a function but a type. I believe one of the most wanted 
changes in the language is about
unfying built-in types and (new-style) classes. A built-in type is not a 
class. However, it is very similar.
If you 'call' it, it acts as a constructor and creates an object of that 
type. It is the same with these:

float,str,tuple,list,long,unicode

and probably many others.

>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?
>
Of course. For example, the literal

1

is an integer object. Integer objects inherit all their methods and 
attributes from their base class.
Acually, they are objects of built-in types but it is almost the same. I 
think that this is very cool.

:-)

Best,

   L 2.0





More information about the Python-list mailing list