Class and Objects In Python

In Python, to define a class, you should use the keyword class
. Here is an example of creating a class in Python.
class Vehicle:
pass
We can see that a class serves as a blueprint. Here, Vehicle
is the class, acting as the blueprint, and it has attributes/variables and methods/functions. Using these tools, we can create the blueprint of the Vehicle
.
To create an object of the Vehicle
class, use the following code:
Vechile_normal_car = Vehicle()
Vechile_super_car = Vehicle()
In the code above, I have created two objects. I can assign them different values and use them accordingly.
In conclusion, we can create many objects from the same class. Therefore, it is important to carefully consider which variables and functions the class should have.
Subscribe to my newsletter
Read articles from Satish Shrishail Mirji directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
