Python Program to find square and cube of a number using class and object
In this program, you will learn how to find square and cube of a number using class and object in Python.
obj = Test()
sq = obj.square(num)
cu = obj.cube(num)
Example: How to find square and cube of a number using class and object in Python
class Test:
def square(self, num):
return num * num
def cube(self, num):
return num * num * num
num = int(input("Enter a number:"))
obj = Test()
sqr = obj.square(num)
cub = obj.cube(num)
print("Square is:", sqr)
print("Cube is:", cub)
Output:
Enter a number:5
Square is: 25
Cube is: 125