CSC148H1 Lecture Notes - Lecture 4: Init, Rational Number

20 views4 pages
3 Feb 2018
School
Course
Professor
katrinasavvy and 38715 others unlocked
CSC148H1 Full Course Notes
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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents