Python Program To Add Two Numbers Using Class
Python program to add two numbers using class is provided on this page.
Python Program To Add Two Numbers Using Class
In this program we define a class named add.
Inside this class we add findaddition() function which accepts two parameters other than self, namely num1 and num2, these are the numbers.
Then in main we simply store two numbers in two variables.
Create object of the add class. Call findaddition() method by passing two variables created in earlier step.
That's it we got the addition of two numbers using class in python.
class add:
def findaddition(self, num1, num2):
sum = num1 + num2
return sum
number1 = 100
number2 = 50
Obj = add()
sum =Obj.findaddition(number1, number2)
print("The sum of two numbers using class is: ", sum)
Related Python Programs
What is tail recursionWhat is maximum possible length of
Lists
Comments