# chapter 4 ## buffet.py foods = ('Cheese', 'Rice', 'Meat', 'Grains', 'Eggs') for food in foods: print(food) #foods[0] = 'Fail' foods = ('Beans', 'Eggs') for food in foods: print(food) # chapter 5 ## conditional_checks.py my_list = [] if not my_list: print("List has no entries in it") my_list.append('Hello') if my_list: print("List has entries now") if my_list: print("It has stuff") else: print("Nope") if 1 == 2: print("This is broke") elif 1 == 1: print("It works") else: print("Its broken") # chapter 6 ## person.py person = {'name': 'thomas', 'age': 25} for key, value in sorted(person.items()): print(key) print(value) for value in person.values(): print(value) for key in person: print(key) for key in person.keys(): print(key)
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