Python Object and Class
As we know python is a multi-lingual programming language (which means it supports different programming approaches). In this article we will see what are objects and classes and how are they created.
One of the recognized approaches to solve a programming difficulty is by creating objects. This is known as Object-Oriented Programming (OOP).
Characteristics of object:
· Attributes
· Behavior
Example:
A dog can be an object, for which;
Attribute: name, age, color
Behavior: barking, chasing, fetching
In python oops focuses on creating re-usable codes. This is known as DRY (Don’t Repeat Yourself).
Class:
A class is a blueprint for the object.
A class is an idea of how something should be defined.
A class is used to create new user defined data structure that contains arbitrary information about something.
Here we have defined an class empty class using class keyword. And dog is the instance (object) of that class.
Object:
An instance is a specific object created from a specific class.
An object is an instantiation of a class. When a class is defined only description of an object is defined, which means no memory or storage is allocated.
Here obj is an object of class dog
Lets now see how to create a class and an object;
With this we have come to the end of this article.
Happy coding…..😊😊😊