Python Classes and Object

 Python Oops concept

Python Classes and Object


Python is an Object-oriented programming. Everything in python is considered as an object. Class is the blueprint or the code template or user defined prototype for creating an object. We have some inbuilt classes like int, str, float.

Example for class and objects in Python

Syntax for creating class:

Class classname:

<statement 1>



<statement n>

Constructors to initialize the variables:

__init__( ), double underscore init double underscore parenthesis is used as constructor in python. It is used to initialize the variables.

Self parameter:

Self is the reference variable and it refers the current instance of the class. There is no rule to use self, it can be named as you like but it should be the first parameter of the function class.


Example for Classes and objects in python


Objects are the instances of the classes or objects are the copy of the classes with actual values. Here in this example, it is not just humans, but they are Sarah and Isaac. You can have n number of human records. Class acts as a guide and it helps to organize the information. 


These are the required properties of an object.


Behaviors are actions that occur on an object. It is defined by functions which are called as methods.

Post a Comment