array = [1,3,3,4,5] print array[0] # will put the number "1" to the screen, because arrays are 0 Indexed (they start counting from 0) print array[1] # will put the number "3" print array[2] # will also, put the number "3" print array[3] # will put the number "4" print array[4] # will put the number "5" ## The "#" means ignore eveything on this line after this, it's called a "Comment", you can uncomment the line below to test it. #print array[5] # will cause an error, as this is out of the array bounds! We've reached the end of our collection, so it can't go any further. class ComplexObject: # First we're declaring the class oneToTen = [1,2,3,4,5,6,7,8,9,10] # declaring a class variable here def addOneToTen(self): x = 0 for val in self.oneToTen: x = x+val return x someObject = ComplexObject() print someObject.addOneToTen() print someObject.oneToTen[0] # this will print "1"
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