OOOPS CONCEPT IN PYTHON

#ASSING VALUE TO ATTRIBUTE IN OOPS


class rectangle:
    length =44
    breadth = 80
R1 = rectangle()
print("initial value of attributes")

print("length",R1.length)
print("breadth",R1.breadth)
print("area",R1.length*R1.breadth)
print("After assigning new value ")
R1.length=56
R1.breadth=56
print(R1.length)
print(R1.breadth)
print("new area", R1.length*R1.breadth)



Output

initial value of attributes
length 44
breadth 80
area 3520
After assigning new value 
56
56
new area 3136


#PRINT USING SELF IN ARGUMENT

class Methodmo:
    def Display_message(self):
        print("welcome to python programming")
o1=Methodmo()
o1.Display_message()

OUTPUT:

welcome to python programming



Q3) DEFINING SELF PARAMETER AND OTHER PARAMETER IN CLASS METHOD


import math
class circle:
    def Cal_Area(self,radius):
        print("radius = " ,radius)
        return math.pi*radius**2
ob1=circle()
print("Area of a circle is ",ob1.Cal_Area(1))

OUTPUT

radius =  1
Area of a circle is  3.141592653589793


Q) Write a program to calculate the area of a rectangle. Pass the length and breadth of the rectangle to the method named Calc_Rect_Area().

CODE:
class Rectangle:
    def Calc_Area_Rect(self,length,breadth):
        print("length = ",length)
        print("breadth = ",breadth)
        return length*breadth
ob1 = Rectangle()
print("Area of Rectangle is ",ob1.Calc_Area_Rect(5,4))

OUTPUT:
length =  5
breadth =  4
Area of Rectangle is  20


Comments

Popular posts from this blog

Sort in specific order (GFG)

Chef and Remissness Problem Code: REMISS (CodeChef)

Short Notes Of computer Network