-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday02_constructors.py
More file actions
68 lines (45 loc) · 1.77 KB
/
Copy pathday02_constructors.py
File metadata and controls
68 lines (45 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#------------------------------------------------------------------------------------------------------------------
#CONSTRUCTORS
#------------------------------------------------------------------------------------------------------------------
#1.Student class with Constructor
class Student:
def __init__(self,name,department):
self.name=name
self.department=department
s1=Student("Nik","CSE")
print("Name:", s1.name)
print("Department:",s1.department)
#-------------------------------------------------------------------------------------------------------------------
#2.Book class
class Book:
def __init__(self,title,author):
self.title=title
self.author=author
b_1=Book("Physics with Fun","RajeshKumar")
print("Title:",b_1.title)
print("Author:",b_1.author)
#---------------------------------------------------------------------------------------------------------------------
#3.Employee Class with Constructor
class Employee:
def __init__(self,name,salary):
self.name=name
self.salary=salary
e1=Employee("Lalith",5000000)
print("\nName:",e1.name, "\nSalary:",e1.salary)
#----------------------------------------------------------------------------------------------------------------------
#4.Area of Rectangle with Constructor and Method
class Rectangle:
def __init__(self,length,breadth):
self.length = length
self.breadth = breadth
def display_area(self):
print("Length:",self.length , "Breadth:",self.breadth)
area = length * breadth
print("Area of the Rectangle:", area)
r1 = Rectangle(14,6)
r2 = Rectangle(45,9)
r3 = Rectangle(60,12)
r1.display_area()
r2.display_area()
r3.display_area()
#------------------------------------------------------------------------------------------------------------------------