'''lecture_25_student.py Our very first class! Represents a Student Oliver W. Layton CS 151: Computational Thinking: Visual Media Fall 2020 TODO: Make Student class with methods: - Constructor with 2 parameters: name and year - get methods - set year method Main code: - Create two students - Get and print their names and years - Set one of their years - Print both years ''' # turtle.forward(100) # calling function # turt.forward(100) # calling method. bc turt is an object of the class Turtle # turt = turtle.Turtle() # making a new object of the call Turtle. # Somewhere in turtle module there is: # class Turtle(): # def __init__(): # # this method is called. # def funA(): # pass # def funB(): # pass # Student class here class Student: # Constructor def __init__(self, name, gradYear): '''This is the constructor self is always the first param for a class method. It is a "bundle of instance variables" for the current object ''' # Create IVs for name and gradYear self.name = name # Tells Python we want to save info as an IV self.year = gradYear # IVs dont need to have same name as params def getName(self): return self.name # I COULD NOT do: #return name # name went away after constructor ended def getGradYear(self): return self.year if __name__ == '__main__': # Symbol table example # jane = Student('Jane', 2024) # print(jane.getYear()) # jane.setYear(2023) jane = Student('Jane', 2024) print('Student\'s name:', jane.getName())