Page 135 - Computer Science Class 11 Without Functions
P. 135

>>> print('Hello')
                 Hello
            In the above example, 'Hello' is the argument passed to the function print(). The function print() may be invoked with
            an arbitrary number of arguments. For example, the following function call makes use of two arguments:

             >>> print('Hello!', 'How are you?')
                 Hello! How are you?
                 Next, we make use of print() function to display the value of an arithmetic expression,
             >>> print(2+14)
                 16
            In the above example, the print() function accepts the argument 2+14, evaluates it, and displays the result of the
            evaluation (16) on the screen. More generally, we may invoke the print() function with several arguments separated
            by commas. For instance,
             >>> print('Sum of',  4, 'and',  5, 'is', 4+5)
                 Sum of 4 and 5 is 9
            When no arguments are specified, the function print() does not output anything, as shown below:
             >>> print()
             >>>
            Next, we would like to mention a refinement of the syntax for using the print() function as follows:
            Syntax:

            print(value, [,…,] [, sep = <separator>])



                   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 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


                                                                                    Basics of Python Programming  133
   130   131   132   133   134   135   136   137   138   139   140