-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntro OOP1.py
More file actions
60 lines (38 loc) · 1.16 KB
/
Copy pathIntro OOP1.py
File metadata and controls
60 lines (38 loc) · 1.16 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
# Object Oriented Programming
# Class and Object in Python
# Robot class
class Robot:
# instance attribute
def __init__(self, name, color, weight):
self.name = name
self.color = color
self.weight = weight
# instance method
def introduce_self(self):
print("My name is : " + self.name)
# instantiate the object 1
# Create an object of Robot
robot1 = Robot("Sadam", "blue", 30)
# call our instance methods
robot1.introduce_self()
# instantiate the object 2
# Create another object of Robot
robot2 = Robot("Ali", "red", 33)
# call our instance methods
robot2.introduce_self()
# person class
class Person:
# instance attribute
def __init__(self, name, personality, is_siting):
self.name = name
self.persoality = personality
self.is_siting = is_siting
# instance methods
def sit_down(self):
self.is_siting = True;
def stand_up(self):
self.is_siting = False;
# instantiate the object 1
person1 = Person("John", "Aggressive", False)
# instantiate the object 2
person2 = Person("Hanan", "Talkative", True)