Page 70 - Information_Practice_Fliipbook_Class11
P. 70
Program 3.5 Fun with Smileys using the argument end.
On execution, the above program produces the following output:
Hello How are you
Note that we have changed the default value of the end from end of line character to the smiley. So, on the execution
of the first call to the function print(), the printer control does not move to the beginning of the next line. Therefore,
the output produced on execution of the next call to the print() function, continues on the same line.
The backslash character '\' is used with escape sequences, such as '\n' and '\t', which are interpreted as newline
and tab characters, respectively.
If any value of the end clause is explicitly given in the print(), then it will be printed at the end of the line. The
statements
print('Welcome to', end='***') → value of end is given as '***'
print('Home','Sweet','Home')
will produce the output as:
Welcome to***Home Sweet Home
The example given below uses both sep and end clauses in the print() :
>>> print(5, 6, 7, 8, sep = '\t', end= '\nOVER')
5 6 7 8 → each value is separated by a tab space('\t')
OVER → the value of end clause is given as newline('\n') followed by 'OVER'
A print() without any argument will print a blank line. If any print() includes a Python expression, the value of
the expression is evaluated before printing, as shown below:
>>> print(1+2, 3*4)
3 12
Finally, let us consider the following print statements and the outputs produced on their execution:
Statements with output
>>> print('Python') # Print a string
Python
>>> print('Python', 'Language') # Two strings are separated by a space
Python Language
>>> print(3*50+42) #Arithmetic expression is evaluated and then printed
192
>>> num = 7
>>> print('Your lucky number is', num) #A string constant and a variable
Your lucky number is 7
>>> print() #A blank line is printed
>>>
>>>print('Python', 'Language', sep='**')#The two strings separated by '**'
Python**Language
>>> print('Python', 'Language', end='@@@') # Output ends with '@@@'
Python Language@@@
>>> print('Python', 'Language', sep='**', end='@@@')
#Use of both sep and end clause
Python**Language@@@
56 Touchpad Informatics Practices-XI

