# Examples to show unformatted and formatted prints # See the handout "print.py" # Matt Bishop, Apr. 9, 2009 # for ECS 10 Spring 2009 # unformatted print num = 1; flnum = 2.6; print "The integer is", num, "and the float is", flnum; # unformatted print, comma at end print "Here is one print statement", print "And here is another" # unformatted print: an adjacent dollar sign print "$", 1.39; # formatted print: an adjacent dollar sign print "$%f" % (1.39); # formatted print: above, but only two decimal places, please! print "$%.2f" % (1.39); # formatted print: print pi to 7 decimal places import math; print "The value of pi is %.7f" % (math.pi); # formatted print with multiple arguments print "%d + %d = %d" % (2, 2, 2 + 2); # very fancy formatted print # using a dictionary instead of a tuple print '%(language)s has %(#)03d quote types.' % \ {"#": 2, 'language': "Python"} # finally, show the string operations x = "2 * %f = %f" % (math.pi, 2*math.pi); print x