The Python Language 4

Understand object-oriented idioms in detail.

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
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
for item in dir(str):
print(item)
...
Access this course and 1400+ top-rated courses and projects.