print()function is very flexible and is able to print several values at the same time. For example, to print
98234539 is a big numberthe program might look like this:
# (1) Print everything as one text print('98234539 is a big number') # (2) Print two space-separated parts print('98234539', 'is a big number') # (3) Print three space-separated parts print('98234539', "is a big", 'number') # (4) Print number instead of text print(98234539, 'is a big', "number")
All of the programs above produce the same output
98234539 is a big number.
- The first version prints the text as a single piece (only a single pair of
- The second one treats
98234539as a separate text, while
is a big numberas another one.
- The third version prints 3 separate text pieces:
is a big, and
- The final version treats
98234539as a number, while
is a bigand
It’s important to note here that the
print()command can print different things: it can print text, and it can print numbers. As shown in the final example, it prints
98234539as a number.
So, when provided with comma-separated-values, the
print()function prints all of them in the output by separating them with a single space.
Write a program that would print these powers of 2:
1 2 4 8 16 32followed by
are powers of two.
Note: Use 1, 2,..., 32 as numbers and
are powers of twoas text.