Python Objects
Every variable in Python is actually an object. You don’t have to write object-oriented (OO) code to use Python, but the way Python is constructed encourages an OO approach. 1
Object Types
All variables have a type that can be seen by using the built-in type() function.
>>> type(23)
<type 'int'>
>>> type('some more text')
<type 'str'>
>>> c=[1,2,'some more text']
>>> type(c)
<type 'list'>
Other types are 'class' , 'module' , 'function' , 'file' , 'bool' , 'NoneType' , and 'long' . The special constants True and False are 'bool' types. The special constant None is a 'NoneType' . To see a textual definition of any object, you can use the str() function; for example, the variable c can be represented as a string:
Every variable in Python is actually an object. You don’t have to write object-oriented (OO) code to use Python, but the way Python is constructed encourages an OO approach. 1
Object Types
All variables have a type that can be seen by using the built-in type() function.
>>> type(23)
<type 'int'>
>>> type('some more text')
<type 'str'>
>>> c=[1,2,'some more text']
>>> type(c)
<type 'list'>
Other types are 'class' , 'module' , 'function' , 'file' , 'bool' , 'NoneType' , and 'long' . The special constants True and False are 'bool' types. The special constant None is a 'NoneType' . To see a textual definition of any object, you can use the str() function; for example, the variable c can be represented as a string:
No comments:
Post a Comment