June 2017
Beginner
320 pages
7h 37m
English
We will now see how to do a more complicated formatting of a string. This code looks complex, but if you do your comments above each line and break each thing down to its parts, you’ll understand it.
ex8.py
1 formatter = "{} {} {} {}" 2 3 print(formatter.format(1, 2, 3, 4)) 4 print(formatter.format("one", "two", "three", "four")) 5 print(formatter.format(True, False, False, True)) 6 print(formatter.format(formatter, formatter, formatter, formatter)) 7 print(formatter.format( 8 "Try your", 9 "Own text here",10 "Maybe a poem",11 "Or a song about fear"12 ))
Exercise 8 Session
$ python3.6 ...
Read now
Unlock full access