Last active
January 4, 2020 00:57
-
-
Save benbagley/84bc683abec1aaf981f76ee4a2306fdf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Same as original gist but this time using OOP. | |
Also use of contructors, class attributes, methods, inheritance/polymorphism etc | |
""" | |
students = [] | |
class Student: | |
school_name = "Springfield Elementary" | |
def __init__(self, name, student_id=332): | |
self.name = name | |
self.student_id = student_id | |
students.append(self) | |
def __str__(self): | |
return "Student " + self.name | |
def get_name_capitalize(self): | |
return self.name.capitalize() | |
def get_school_name(self): | |
return self.school_name | |
class HighSchoolStudent(Student): | |
school_name = "Springfield High School" | |
def get_school_name(self): | |
return "This is a high school student" | |
def get_name_capitalize(self): | |
original_val = super().get_name_capitalize() | |
return original_val + "-HS" | |
james = HighSchoolStudent("james") | |
print(james.get_name_capitalize()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment