Is a list an instance of a class?

Kent Johnson kent3737 at yahoo.com
Sun Nov 14 15:33:44 EST 2004


In the Python tutorial section 9.1, it says, "the word ``object'' in 
Python does not necessarily mean a class instance. Like C++ and 
Modula-3, and unlike Smalltalk, not all types in Python are classes: the 
basic built-in types like integers and lists are not, and even somewhat 
more exotic types like files aren't."

Is this still correct or was it made obsolete by Python 2.2? Lists and 
files have __class__ attributes, at least:

 >>> [].__class__
<type 'list'>
 >>> f = open('ThreadQueue.py')
 >>> f.__class__
<type 'file'>

So do integers and floats, though you have to ask nicely for an int:
 >>> 1.__class__
   File "<stdin>", line 1
     1.__class__
               ^
SyntaxError: invalid syntax
 >>> x=1
 >>> x.__class__
<type 'int'>
 >>> 0.5.__class__
<type 'float'>

Kent



More information about the Python-list mailing list