-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay_ 30 Constructors.py
59 lines (40 loc) · 1.18 KB
/
Day_ 30 Constructors.py
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
# Day_ 30 Constructors in Python .........................................................................................
# class Point:
# def __init__(self, x, y):
# self.x = x
# self.y = y
# def move(self):
# print("move")
# def draw(self):
# print("draw")
# point = Point(10, 20)
# print(point.x)
# EXERCISE # 1: Make a class person wit two attributes name and talk
# class Person:
# def talk(self):
# print("talk")
# def name(self):
# print("name")
# person = Person()
# person.talk()
# person = Person()
# person.name()
# Second method to write it using constructors
# class Person:
# def __init__(self, name):
# self.name = name
# def talk (self):
# print("talk")
# person = Person("Haris")
# print(person.name)
# person.talk()
# Third method to write it using constructors and functions
# class Person:
# def __init__(self, name):
# self.name = name
# def talk (self):
# print(f"Hi I am, {self.name} ")
# person1 = Person("Haris")
# person1.talk()
# person2 = Person("Shakir")
# person2.talk()