(License: CC BY-SA 4.0)
Prev - Python basics refresher, Next - Errors and Exceptions
Module 3 from Python Essentials 2 (old resource: HyperSkill )
No teamwork; change example below (not just the strings!):
class Gunay:
# class attributes
classname = "python"
school = "ggc"
# constructor with instance attributes
def __init__(self, firstname, lastname, pet, sport, vacation):
self.firstname = firstname
self.lastname = lastname
self.pet = pet
self.sport = sport
self.vacation = vacation
# additional method
def greeting(self):
print("Hello, I am " + self.firstname + " " +
self.lastname + " and I like " + self.sport +
" while I am vacationing at " + self.vacation)
print("I'm in the " + self.classname + " course at " + self.school + " like everyone else.")
super()
methodsuper()
at least onceWork individually, follow instructions:
PythonClass
belowsuper()
method in your constructor__str__
method to compose a message about yourself__str__
method with your instanceclass PythonClass:
school = "GGC"
degree = "IT"
classname = "ITEC 3160"
members = []
def __init__(self, fname, lname):
self.fname = fname
self.lname = lname
self.member = "student"
PythonClass.members.append(self)
def __str__(self):
return self.fname + " " + self.lname + " (" + self.member + ")"