CSC148H1 Lecture Notes - Lecture 4: Init, Rational Number
katrinasavvy and 38715 others unlocked
1
CSC148H1 Full Course Notes
Verified Note
1 document
Document Summary
Class attributes refer to a variable instantiated in a class; this means that every instance of that class will have the same variable, unless overwritten. The height of a human in cm. iq: int age: int height: int def __init(self, age: int, height: int) -> none: This method is run automatically whenever an instance of a class is created, so there is no need, and is incorrect, to directly call it. self. age = age self. height = height self. iq = 100. So each instance of a human class will have an iq of 10, and each human will also have a height and age, so these are all class attributes. So when it is called in the python console: # this creates a new instance attribute for a. # notice how the fact that each human starts off. # with the value 100 for their iq does not change. # only the specific instance, a, has been changed.