An object is an instance of a class, objects have the behaviours of their class.
The object is the actual component of programs, while the class specifies how instances are created and how they behave. method: a method is an action which an object is able to perform.
Class is a blueprint or template from which objects are created. Object is a real world entity such as pen, laptop, mobile, bed, keyboard, mouse, chair etc. Class is a group of similar objects.
Objects are an encapsulation of variables and functions into a single entity. Objects get their variables and functions from classes. Classes are essentially a template to create your objects.
class Calculator:
n1=0
n2=0
def Add(a):
print("Sum of ",a.n1," and ",a.n2," is : ",(a.n1+a.n2))
def Sub(s):
print("Subtraction of ",s.n1," and ",s.n2," is : ",(s.n1-s.n2))
def Mult(m):
print("Multiplication of ",m.n1," and ",m.n2," is : ",(m.n1*m.n2))
def Div(d):
print("Division of ",d.n1," and ",d.n2," is : ",(d.n1/d.n2))
obj=Calculator()
n=int(input("1.Addition\n2. Subtraction\n 3.Multiplication\n 4. Division\n"))
obj.n1=int(input("Enter 1st Number"))
obj.n2=int(input("Enter 2nd Number"))
if(n==1):
obj.Add()
elif(n==2):
obj.Sub();
elif(n==3):
obj.Mult();
elif(n==4):
obj.Div()