CMPT 120 Lecture Notes - Lecture 30: Init

33 views2 pages
meghan78 and 39786 others unlocked
CMPT 120 Full Course Notes
29
CMPT 120 Full Course Notes
Verified Note
29 documents

Document Summary

Class definition: set of statements that define a class"s methods and data attributes. Class names often start with uppercase letter. Method definition like any other python function definition. Self parameter: required in every method in the class references the specific object that the method is working on. Initializer method: automatically executed when an instance of the class is create. Initializes object"s data attributes and assigns self parameter to the object that was just created. Usually the first method in a class definition: an object is created in memory from the coin class, the coin class"s __init__ method is called, and the self parameter is set to the newly created object. After these steps take place, a coin object will exist with its sideup attribute set to heads". To create a new instance of a class call the initializer method. To call any of the class methods using the created instance, use dot notation.

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

Related Questions