The Python Language 4
In Python, everything is considered an object, allowing the use of functions like type() to reveal an object's class. The dir() function lists a class's methods and attributes, exemplified by the str class's numerous capabilities. Classes are defined using the class keyword, with attributes and methods added at class scope, while instance attributes require a self parameter and the __init__ method during object creation. Python also supports inheritance, including multiple inheritance, though the latter should be used sparingly.
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:
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: ...