Page 69 - Information_Practice_Fliipbook_Class11
P. 69

In the syntax description, the values/items enclosed in the square brackets [] are optional.


            The syntax [,…,]  indicates that while invoking the function print(), one can specify any number of values
            separated by commas. As the function  print() may be invoked without any arguments also, above description of
            Python syntax may be revised as follows:
            Syntax:

            print([value, [,…,]] [, sep = <separator>])
            Sometimes, we will use the following notation to express repetition:

            Syntax
            print([value1, value2, …, valueN] [, sep = <separator>])
            Further, programmers can override the default separator space by specifying one of their choice. For example,

             >>> print('Sum of',  4, 'and',  5, 'is', 4+5, sep ='   ')
                 Sum of   4   and   5   is   9

            Note that the values displayed by the print() function are now separated by three spaces instead of one.
            Finally,  we would like to mention a further refinement of the syntax for the print() function as follows:

            print(value, [,…,] [ sep = <separator>, end = <endmarker>])
            We already know that, by default, the output produced on invoking the print() function terminates the output line.
            Indeed, we have already seen that the output produced by invoking  the print() function multiple times appears
            on separate lines. Sometimes, we may like the output to appear with double line spacing. This may be achieved as
            follows:

             >>> print('Hello', end = '\n\n')
                 Hello
             >>> print('Welcome to Python Programming', end = '\n\n')
                 Welcome to Python Programming
            Note that the backslash character '\' used with escape sequences, such as '\n' and '\t', is interpreted as newline and
            tab characters, respectively.
            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 3.4):

            # Objective: Fun with smileys
            print('Hello', end = '\N{slightly smiling face}')
            print('How are you', end = '\N{slightly smiling face}')




                                                                                    Basics of Python Programming  55
   64   65   66   67   68   69   70   71   72   73   74