Advanced printing - end
print()is used to print something, the next
print()already prints from a new line. But in some cases, you might want to stay on the same line.
print('hello', 'everyone', end='...') print('Anyone here?')
This program would print
hello everyone...Anyone here?. So, instead of printing
Anyone here?from a new line, the program stayed on the same line as
endwas set to
By default, the
endparameter is set to
\n, which is a special symbol that represents the new line. We will cover the special symbols and what they do later in the course. For now, we’ll cover only one -
\nthe new line symbol.
print('one', 'two', end='--') print('three', 'four', end='!!!') print('five', 'six', 'seven', end='\n') print('eight', end='nine') print('ten', end='... the end...')
This program would result in:
one two--three four!!!five six seven eightnineten... the end...
Use 12 print statements to print all the months in a year. At the end of each month, there should be a
*-*except for the last one.
Here is the list of all months: January, February, March, April, May, June, July, August, September, October, November, and December.
Time limit: 1 seconds
Memory limit: 512 MB
Output limit: 1 MB