Introduction to Python Class

Python is an object oriented programming language. Almost everything in Python is an object, with its properties and methods.

Class is like an object constructor, a "blueprint", or  an outline for creating a new object. An object is anything that can be manipulated  or changed  while working through the code. Every time a class object is instantiated, which means when we declare a variable, a new object is initiated from scratch.

Class objects can be used over and over again whenever needed. It is a prototype from which objects are created.

It creates a user-defined data structure, which holds its own data members and member functions, which can be accessed and used by creating an instance of that class. 

Like function definitions begin with the def keyword in Python, class definitions begin with a class keyword.

Class Definition Syntax:

class ClassName:
    # Statement-1
    #Statement-2
    .
    .
    #Statement-N

Example:

Class apple:
    pass

In the above example, the class keyword indicates that you are creating a class followed by the name of the class.

Tags