Is a list an instance of a class?

Kent Johnson kent3737 at
Sun Nov 14 21:33:44 CET 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('')
 >>> f.__class__
<type 'file'>

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


More information about the Python-list mailing list