Page 136 - Computer Science Class 11 With Functions
P. 136

Before we close this section, let us have some fun with the print() function. Python allows us to display emojis in a very
        simple manner. For example,

         >>> print('\N{slightly smiling face}')
                
         >>> print('\N{winking face}')

                
        Next, we like to print some text separated by emojis as follows:

         >>> print('Happy',2,'help', sep = '\N{slightly smiling face}')

              Happy  2  help
        Next, let us print the same message, terminated by three emojis.
         >>> print('Happy',2,'help', sep = '\N{winking face}', end = 3*'\N{winking face}')

              Happy  2  help      
        Finally, we encourage you to execute the following Python script (Program 6.5):

         Program 6.5 Fun with Smileys using the argument end.

              # Objective: Fun with smileys
              print('Hello', end = '\N{slightly smiling face}')
              print('How are you', end = '\N{slightly smiling face}')
        On execution, the above program produces the following output:
              Hello  How are you  
        Note that we have changed the default value of end from end of line character to the smiley. So, on 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






         134   Touchpad Computer Science-XI
   131   132   133   134   135   136   137   138   139   140   141