-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (46 loc) · 1.41 KB
/
Copy pathmain.py
File metadata and controls
58 lines (46 loc) · 1.41 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
class StudentInfor:
def Print(self):
if len(self.name) <= 0:
return 'Name is empty.'
else:
if self.grade == 100:
return True
else:
print('Your name:',self.name)
return False
def __init__(self, name, grade):
self.name = name
self.grade = grade
#Creating an object and attributes without init.
# student1 = StudentInfor()
# student1.name = 'Thao Pham'
# student1.grade = 100
# print(student1.Print())
#Creating an object and attributes without init.
# student2 = StudentInfor()
# student2.name = input('Please enter your name for the 2nd object:')
# student2.grade = input('Please enter your grade:')
# print(student2.Print())
student3 = StudentInfor('Thao Pham', 100)
print(student3.name)
print(student3.grade)
print(student3.Print())
print(type(StudentInfor))
print(student3.__dict__)
print(student3.__module__)
print('\n###################################\nInheritance: inherit attributes and methods from a parent clas to child class')
class Animal: #Creating a parent class
def speak(self):
print('This animal can', end=' ')
class Dog(Animal): #creating a child class
def bark(self):
print('bark')
class Cat(Animal): #creating a child class
def meow(self):
print('meow')
dog1 = Dog() #Creating object of Dog()
dog1.speak()
dog1.bark()
cat1 = Cat()
cat1.speak()
cat1.meow()