I am currently exploring the topic of objects a little more. Once you go a bit deeper into the topic, it can get quite complex and confusing (at least at first).

What is pretty cool though is realizing that in Python, everything is an object. Basically, every value or data type is an instance of a class.

For example, creating a new string like my_name = 'Peter' actually creates an object of the class str. That’s why we can also use methods such as upper() (and many others) as these come with the class.

As I was exploring all these objects, I found a very useful built-in function called help(), which displays the documentation or information about a module, function or object.

The help() Function

The help() function in Python is used to display the documentation or information about a module, function, or object. When called with no arguments, it opens an interactive help session. When called with a specific argument, it returns the documentation for that argument. For example, calling help(print) would display the documentation for the built-in print function.

You can also use help() for exploring python class and its methods. e.g help(str) will give you all the methods available for string class.

Let’s say we have a (very simple) class named Car.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
class Car:

	def __init__(self, model, max_speed):
		self.model = model
		self.max_speed = max_speed

	def update_speed(self, speed):
		self.max_speed = speed

	def update_model(self, model):
		self.model = model

Now we can instantiate a new Car object as follows.

1
bmw = Car('BMW', 220)

Now if we want to understand the Car object we can call help(bmw) or help(Car) which prints details about the class.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
Help on class Car in module __main__:

class Car(builtins.object)
 |  Car(model, max_speed)
 |
 |  Methods defined here:
 |
 |  __init__(self, model, max_speed)
 |      Initialize self.  See help(type(self)) for accurate signature.     
 |
 |  update_model(self, model)
 |
 |  update_speed(self, speed)
 |
 |  ---------------------------------------------------------------------- 
 |  Data descriptors defined here:
 |
 |  __dict__
 |      dictionary for instance variables (if defined)
 |
 |  __weakref__
 |      list of weak references to the object (if defined)

This becomes very helpful when we are working with large and/or unfamiliar objects. We can see its methods, attributes, method resolution order (chain of inheritance) and probably a lot more stuff which I have yet to learn myself.