I&C SCI 33 Lecture Notes - Lecture 7: Init, Class Variable, Instance Variable

54 views5 pages

Document Summary

It calls a special function that creates an object that is a new instance of the class: note that this object automatically has an dictionary associated with it, with the name __dict__, and that dictionary starts empty. Manipulating an object"s namespace (and __init__: all objects have namespaces, which are dictionaries in which attribute names defined in that object are bound-to/associated-with values. This creates an entry in the __dict__ that looks like: {name: value: alternate (not recommended) ways: c = c() c. x = 1 c. __dict__["z"] = 3 print(c. __dict__) --> prints {"x":1, "z": 3} This way, we can place limits on the parameters the user enters: once an object is constructed/initialized, we use it by calling methods on it. *remember: o. m() is translated into type(o). m(o,: note about if __name__ == "__main__" with the file/module name it was written in. If a module were imported, the __module__ key in the object dictionary would be associated.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents