#!/usr/bin/python
# Simple python examples
# python/examples/printing1.py
# David MacKay and Sanjoy Mahajan
print "Hello world"
x = "Hello World"
print "The value of x is", x
# You can use either single or double quotes
# to enclose strings
print 'Also, the value of x is', x
print "Multiple lines: The value\n of x\n is", x
i = 123
j = 99
y = 123.45678912345
print "d - an integer: %d" % (i)
print "f - a floating point number: %f" % (y)
print "f - a floating point number: %6.2f" % (y)
print "f - a floating point number: %6.1f" % (y)
print "g - a float in scientific notation: %g" % (y)
print "g - more scientific notation: %6.2g" % (y)
print "s - The value of my string is %s" % (x)
print "int with 4 characters space: %4d %4d" % (i,j)
print "int with 4 characters space: %4d %4d" % (j,i)
# The print statement automatically includes a newline
# at the end of the output.
# To prevent the automatic newline add a comma
print "d - an integer: %d " % (i) ,
print "f - a floating point number: %f" % (y)
# The standard backslash characters (\n, \t, etc.)
# are recognized.
# If you want to print backslashes, you can turn off the
# backslash feature by preceding the string with 'r' -
print r"Raw string with \n and \t in it"
print "String with \n and \t in it"
print """Tripling-quoting is also permitted"""
|