Format Strings

Exercise 1

Try the following expressions in a Python shell:

"{}".format("Hello")
"{:10}".format("Hello")
"{:>10}".format("Hello")
"{1} {0}".format("first", "second")
"{:5d}".format(42)
"{:4.1f}".format(3.14159)
"{:6.3f}".format(3.14159)

Exercise 2

Write a for loop producing the following string:

000111222333444555666777888999

Exercise 3

You have the following two lists:

top_ten_names = ['Jacob', 'Michael', 'Matthew', 'Joshua', \
    'Christopher', 'Nicholas', 'Andrew', 'Joseph', \
    'Daniel', 'Tyler']

top_ten_numbers = [34465, 32025, 28569, 27531, \
    24928, 23632, 22818, 22307, 21500]

Write a program that creates a table with two vertically aligned columns.

results matching ""

    No results matching ""