######################################## mynumber = 5 print "Python 2:" print "The number is %d" % (mynumber) print mynumber / 2, print mynumber // 2 from __future__ import print_function from __future__ import division print('\nPython 3:') print("The number is {}".format(mynumber)) print(mynumber / 2, end=' ') print(mynumber // 2) from __future__ import braces mylist = ["It's", 'only', 'a', 'model'] for index, item in enumerate(mylist): print(index, item) mynumber = 3 if 4 > mynumber > 2: print("Chained comparison operators work! \n" * 3) from collections import Counter from random import randrange import pprint mycounter = Counter() for i in range(100): random_number = randrange(10) mycounter[random_number] += 1 for i in range(10): print(i, mycounter[i]) my_phrase = ["No", "one", "expects", "the", "Spanish", "Inquisition"] my_dict = {key: value for value, key in enumerate(my_phrase)} print(my_dict) reversed_dict = {value: key for key, value in my_dict.items()} print(reversed_dict) import subprocess output = subprocess.check_output('dir', shell=True) print(output) my_dict = {'name': 'Lancelot', 'quest': 'Holy Grail', 'favourite_color': 'blue'} print(my_dict.get('airspeed velocity of an unladen swallow', 'African or European?\n')) for key, value in my_dict.iteritems(): print(key, value, sep=": ") a = 'Spam' b = 'Eggs' print(a, b) a, b = b, a print(a, b) my_dict = {'That': 'an ex-parrot!'} help(my_dict) my_long_text = ("We are no longer the knights who say Ni! " "We are now the knights who say ekki-ekki-" "ekki-p'tang-zoom-boing-z'nourrwringmm!") print(my_long_text)