Title: Formatted Output Examples
Course: CPS 120: Introduction to Computer Science ~ Master (Aug/2015) OLD > Section: Learning Units

# Left-justify string in a field
print ("{0:16s}".format(“December”))

Prints this (without the hyphens):
123456789|123456789|123456789|123456789|123456789|123456789|
December--------

# Right-justify string in a field
print ("{0:>16s}".format(“October”))

Prints this (without the hyphens):
123456789|123456789|123456789|123456789|123456789|123456789|
---------October

# Format three strings on same line
print ("{0:>10s}{1:10s}{2:10s}".format(“WCC”, “OCC”, “LCC”))

Prints this (without the hyphens):
123456789|123456789|123456789|123456789|123456789|123456789|
-------WCCOCC-------LCC-------

# Right-justify integer in a field
print ("{0:10d}".format(714))

Prints this (without the hyphens):
123456789|123456789|123456789|123456789|123456789|123456789|
-------714

# Left-justify integer in a field
print ("{0:<10d}".format(89))

Prints this (without the hyphens):
123456789|123456789|123456789|123456789|123456789|123456789|
89--------

# Right-justify real-number in a field
print ("{0:10.2f}".format(3.14))

Prints this (without the hyphens):
123456789|123456789|123456789|123456789|123456789|123456789|
------3.14

# Left-justify real-number in a field
print ("{0:<10.2f}".format(0.45))

Prints this (without the hyphens):
123456789|123456789|123456789|123456789|123456789|123456789|
0.45------