-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathclass.py
More file actions
40 lines (30 loc) · 941 Bytes
/
class.py
File metadata and controls
40 lines (30 loc) · 941 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Python = Object Oriented Programming Language
# Almost everything in Python is object with properties and methods
# Class = Blueprint
# class Person:
# x = 5
# p1 = Person()
# print(p1.x)
# init function
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def greeting(self):
print("Hello, my name is " + self.name)
p1 = Person("Abdi", 30)
# print(p1.name, p1.age)
# p1.greeting()
# p1.age = 31
# del p1.age
# print(p1.age)
#Subclass/Parent-Child Class/Inheritance
class Student(Person):
def __init__(self, name, age, graduationyear):
super().__init__(name, age)
self.graduationyear = graduationyear
def welcome(self):
print("Congratulations " + self.name + " Welcome to the class of", + self.graduationyear)
student1 = Student("Jamaal", 25, 2020)
student2 = Student("Hamdi", 26, 2021)
student2.welcome()