-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path42_oops.py
More file actions
26 lines (20 loc) · 761 Bytes
/
42_oops.py
File metadata and controls
26 lines (20 loc) · 761 Bytes
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
class human:
def __init__(self, name, age): #this is a constructor
self.name = name
self.age = age
#ab banaate hain object:
person1 = human("sohom",22)
person2 = human("Riya",21)
print(person1.name)
print(person2.age)
class Employee: #this is how a class is written
language = 'python' #this is a class attribute
salary = 1200000 # this is a class attribute
harry = Employee()
harry.name = "Harry" # this is a object attribute
print(harry.name, harry.language, harry.salary)
rohan = Employee()
rohan.name = "Rohan Roro Robinson"
print(rohan.name, rohan.language, rohan.salary)
# here name is object attribute.
# salary and language are class attributes as they directly belong to the class.