#from module import classname class Point: #creating a new class (usually in seperate file) #using a class, p = Point(), p = reference, p.x = 3, creates a variable called x in Point with 3 as a value def __init__(self, xloc, yloc): #class definition is (self... ) self.x = xloc #creates a variable called x at location self (where the class is in memory), gives it xloc self.y = yloc def translate(self, dx, dy): self.x += dx #gets us to the object self.x, then adds to it what is dx self.y += dy #Exercise 1: class of square with length of side #from geometry import square class square: def __init__(self, side): self.side = side
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question