We know that Python is an object oriented programming language. So it's main focus is class and object. Here when a function will be invoked by object then function definition will execute.
In object oriented programming language,object is a memory containing data and function to manipulate data.
As we know a class is a grouping of objects having identical properties, common behavior, and shared some relationships to perform a specified task.
Example: a computer system, a vehicle etc.
But in programming point of view a class is a user-defined data type which fully defines an object. That means without a class, we cant declare an object
An object is a named memory allocation which contains class property.
A class contains data or function or data and function which is considering as class property.
Once a class is declared, we can take any no of objects belonging to that class.
Python classes contain all the standard features of Object Oriented Programming. Lets see an example for better understanding:
#Develop a python program to display a message class MyExample1: def show(self); print("python means pythontpoints.com") obj=MyExample1() #object declaration obj.show() #Message Passing
Python means pythontpoints.com
#Develop a python program to display your full name class MyExample2: def get(self,fname,lname); self.fname=fname self.lname=lname def show(self): print("The full name is",self.fname,self.lname) obj=MyExample2() #object declaration obj.get("Sanghamitra","Mohanty") obj.show()
The full name is Sanghamitra Mohanty
#Develop a python program to find the area of a trianle class AreaTriangle: def get(self,base,height): self.base=base self.height=height def area(self): a=0.5 * self.base * self.height print("The area of triangle is", a) obj=AreaTriangle() obj.get(2.3,4.5) obj.area()
The area of triangle is 5.175
#Develop a python program to find the factorial of a number using class and object class Factorial: def get(self,n): self.n=n def fact(self): i=1 f=1 while i<=self.n: f=f*i i+=1 print("the factorial is",f) obj=Factorial() #object declaration obj.get(5) obj.fact()
the factorial is 120
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc