© Paul Gerrard 2016
Paul GerrardLean Python10.1007/978-1-4842-2385-7_2

2. Python Objects

Paul Gerrard
Maidenhead, Berkshire, UK
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 ...

Get Lean Python: Learn Just Enough Python to Build Useful Tools now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.