# variable name = "Hing Garden" #upper or lower print name.upper() #len() len(Hing Garden) print Hing Garden.upper() #if/elif/else if 5 < 6: print "i get printed" elif 5 < 6: print "I don't get printed!" else: print "I also don't get printed!" #a boolean operator 5 <3 and 2 < 1 is False #list HingGarden_food = ["beef""chicken""shrimp""lobster"] if len(HingGarden_food) > 3: print "The first food at the HingGarden is the" + HingGarden_food [0] print "The second food at the HingGarden is the" + HingGarden_food [1] print "The third food at the HingGarden is the" + HingGarden_food [2] print "The fourth food at the HingGarden is the" + HingGarden_food [3] #a function def tax(bill): """Adds 8% tax to a restaurant bill.""" bill *= 1.08 print "With tax: %f" % bill return bill def tip(bill): """Adds 15% tip to a restaurant bill.""" bill *= 1.15 print "With tip: %f" % bill return bill #an arithmetic operator meal_cost = 100 meal_with_tax = tax(meal_cost) meal_with_tip = tip(meal_with_tax) #for loop print "Counting..." for i in range(20): print i
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