In this post I am going to describe to you Classes and Objects in Python, What is the role and how to present Classes and Objects In Python?
What is a class?
As python is an object-oriented programming language, it has the references of class and object. A class is a real-life entity having similar characteristics, also referred to as a blueprint for creating objects.
What is an object?
An object is an instance of a class which helps to call the class, class methods etc.
How to create a class and object?
Syntax: class Classname: #class definition - - #body -
Let us see an example:
class ClassMy: #class definition name="Abcd" age=15 c=ClassMy() #object creation print("The name=",c.name) print("The age=",c.age)
This was a short and simple discussion of class and object in python. It is a very important topic to deal with several projects in python. Hope your doubts were cleared.
If you wants to contribute Like this article please WhatsApp us.
Please comment and share this post if you like.