Monday, March 15, 2021

Classes and Objects in OOPS - a short introduction in Python

 


     Classes and Objects in OOPS

 

* A Class is a model or plan to create objects . This means , one can write a class with the attributes and actions of objects .

 

* Attributes are represented by variables and actions are performed by methods. Therefore , a class contains both variables and methods .

 

* The same variables and methods are also available within the objects because the objects are created from the class to which the variables and methods belong.

 

* These variables are also called as 'instance variables' because these instance variables can be created inside an instance like an object .

 

* One should remember the difference between a function and a method. A function which is written inside a class is called as a Method.

 

* Generally, a Method is called using one of the following two ways :

1) classname.methodname()

2) instancename.methodname()

 

 

* The general format of a class is given in the following manner:

Class Classname(object):

def _init_(self):

def method01():

def method02():

 

No comments:

Post a Comment