# # first # num = 1 flnum = 2.6 print("The integer is", num, "and the float is", flnum) # # second # print("--------------------------------------") print("Here is one print(statement") print("And here is another") # # third # print("--------------------------------------") print("Here is one print(statement", end=' ') print("And here is another") # # fourth # print("--------------------------------------") print("$", 1.39) # # fifth # print("--------------------------------------") print("$%f" % (1.39)) # # sixth # print("--------------------------------------") print("$%.2f" % (1.39)) # # seventh # print("--------------------------------------") import math print("The value of pi is %.7f" % (math.pi)) # # eighth # print("--------------------------------------") for i in range(1, 5): print("%.2f" % (math.pi * i)) # # ninth # print("--------------------------------------") for i in range(1, 5): print("%5.2f" % (math.pi * i)) # # tenth # print("--------------------------------------") print("%d + %d = %d" % (2, 2, 2 + 2)) # # eleventh # print("--------------------------------------") print("%(language)s has %(#)03d quote types." % {"#":2, 'language':"Python"}) # # twelfth # print("--------------------------------------") print("{} is different than {}".format("Python 2", "Python 3")) # # thirteenth # print("--------------------------------------") print("{0} {1} is different than {0} {2}".format("Python", 2, "3")) # # fourteenth # print("--------------------------------------") print("{language}s have {Q:03d} quote types.".format(Q=2, language="Python")) # # fifteenth # print("--------------------------------------") print("The value of pi is {0:.7f}".format(math.pi)) # # sixteenth # print("--------------------------------------") print("This prints to the left in the field: '{0:<6}'".format('text')) print("This prints to the right in the field: '{0:>6}'".format('text')) print("This prints in the center of the field: '{0:^6}'".format('text')) # # seventeenth # print("--------------------------------------") x = "2 * %f = %f" % (math.pi, 2*math.pi) print(x) # # eighteenth # print("--------------------------------------") x = "2 * {0:.6f} = {1:.6f}".format(math.pi, 2*math.pi) print(x)