The Python Language 4
Understand object-oriented idioms in detail.
We'll cover the following...
We'll cover the following...
Objects and classes
Everything in Python is an object.
For example, if we use the type()
function introduced earlier, we can see:
Press + to interact
Python 3.5
print(type('hello')) # outputs <class 'str'>
So, hello
is an instance of the str
class. We can use the built-in dir()
function to list the methods and attributes of a class:
Press + to interact
Python 3.5
for item in dir(str):print(item)
We can see that ...