-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex08.py
More file actions
20 lines (18 loc) · 875 Bytes
/
ex08.py
File metadata and controls
20 lines (18 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Exercise 8: Printing, Printing
# http://learnpythonthehardway.org/book/ex8.html
# formatting characters can have different types
formatter = "%r %r %r %r"
# formatter = "%s %s %s %s" works as well, because (1, 2, 3, 4) can be strings as well ("downward compatible")
# formatter = "%d %d %d %d" can't work, because ("one", "two", "three", "four") can't be decimal numbers
# Displaying different insertions into above variable
# always same as print "%r %r %r %r" % ...
print formatter % (1, 2, 3, 4)
print formatter % ("one", "two", "three", "four")
print formatter % (True, False, False, True)
print formatter % (formatter, formatter, formatter, formatter) # recursive insertion
print formatter % (
"I had this thing.",
"That you could type up right.",
"But it didn't sing.", # internal ' will make output be surrounded by "", rather than ''
"So I said goodnight.",
)