-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClassBasic.py
42 lines (31 loc) · 940 Bytes
/
ClassBasic.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
class MyClass:
x = 5
class MyPerson:
def __init__(self, name, age):
self.name = name
self.age = age
def my_func(self):
print("Hello, my name is {}".format(self.name))
class Person:
def __init__(self, fname, lname):
self.fname = fname
self.lname = lname
def print_name(self):
print(self.fname, self.lname)
class Student(Person):
def __init__(self, fname, lname, year):
super().__init__(fname, lname)
self.graduation_year = year
def welcome(self):
print("Welcome {} {} to the class of {}".format(self.fname, self.lname, self.graduation_year))
if __name__ == "__main__":
myClass = MyClass()
print(myClass.x)
myPerson = MyPerson("ABC", 20)
print(myPerson.name, myPerson.age)
myPerson.my_func()
x = Person("Alex", "Hu")
x.print_name()
x = Student("ABC", "DEF", 2020)
x.print_name()
x.welcome()