


















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















































A Basic Introduction Coming up: Topics 1
Circle Class Attributes:
class Circle(object): def init(self, center, radius): self.center = center self.radius = radius def draw(self, canvas): rad = self.radius x1 = self.center[0]-rad y1 = self.center[1]-rad x2 = self.center[0]+rad y2 = self.center[1]+rad canvas.create_oval(x1, y1, x2, y2, fill='green') def move(self, x, y): self.center = [x, y] Beginning of the class definition The constructor. This is called when someone creates a new Circle, these assignments create attributes. A method that uses attributes to draw the circle A method that sets the center to a new location and then redraws it objects/CircleModule.py
myCircle = Circle([10,30], 20)
myCircle = Circle([10,30], 20)
CENTER :(10, 30) To get an instance variable from an object, use: <
myCircle = Circle([10,30], 20) print "CENTER :"+str(circle.carl)
AttributeError: Circle instance has no attribute ’carl’
Summary: Using instance variables