COMPSCI 61A Chapter Notes - Chapter 2.5: Init, Object-Oriented Programming

57 views2 pages
zogo39484755 and 6 others unlocked
COMPSCI 61A Full Course Notes
22
COMPSCI 61A Full Course Notes
Verified Note
22 documents

Document Summary

A function value that is created by a def statement within a class statement is bound locally within the class as an attribute. Methods are the functions that are bound to an object. Functions defined in a class are not methods until an instance of the class is created. Then, then functions are called the methods of the newly created object. All invoked methods have access to the object instance via self parameter, in which they can access and manipulate the object"s state def (self, ): self. = return . When a method (not the class"s function) is invoked, that object is implicitly passed as the first argument to the method. >>>account. deposit(spock_account, 1001) #deposit function takes in 2 arguments. >>>spock_account. deposit(1000) # deposit method takes in 1 argument. constructor - the method that initializes the class"s objects def __init__(self, ): self. = Note: not every class needs to have a method __init__ ( when a class needs an __init__)

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