CS 110 Study Guide - Final Guide: Graphical User Interface, Init

113 views3 pages

Document Summary

To create a class called circle, the class is called by class circle: The magic methods are the functions __init__ and __str__. def __init__(self, parameters) is the function that is called when an object of the class is created. The method is used to create instance variables for an object. For example: class circle: def __init__(self,radius): self. radius = radius self. area = (radius**2)*math. pi. When the print() method is called by: print(circ) the __str__ function is called, and what is returned is printed. Within a class, a function must have certain properties. One such property is that the parameter self must always be in a function, including the magic methods. The reason why is because methods are called on an object of the class, so the method must only affect that object"s instance variables. The object itself is automatically seen as a parameter, because of this.

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

Related Documents

Related Questions