# # # def main(): x=0 # while (x < 5): #loops are alot simpler in python only if # print x #for loops,,, uses range of numbers # x = x + 1 #######Alternative way to do this##################################################### # for x in range(5,10): #keep your indentation perfect!!! 2 spaces # print x #############Range for days version ######################################################################### # days = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"] # for d in days: # print d ################Breaks in Loops################################################################################################ # for x in range(5,10): # if (x == 7): break #what this does is that it stops the loop # if (x % 2 == 0): continue # will only progress in increments of two # print x ############Enumeration########################################################################################## days = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"] for i, d in enumerate (days): #enumerate means put numbers on the amounts print i, d if __name__== "__main__": main() #all of these loops require this final statement
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