Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 93 - 2629_Devagiri_C-6
P. 93

    Syntax of print() function:
     OPENING AN EXISTING PROGRAM
                     print(<value>)
     You can open an existing Python program to make changes or run it again. To open an existing   Here, the value can be an expression, string or variable that you want to display. You can also
     Python program, follow the given steps:  print multiple items by separating them with commas.

                     For example:
     1    Click on the File menu.  4    Select the program file.
                     print("Let's code together!")

     2    Click on the Open option.   >>> Let's code together!
     The Open dialog box will   Program 1  To use the input( ) and print( ) functions.
     appear.
     3    Navigate to the   Program1.py
     location where you
     have saved your file.  5    Click on the Open button.  File  Edit  Format  Run  Options  Window  Help

                       name = input("Enter your name: ")
     The selected Python program is now open in the editor, ready for you to modify or execute.
                       print("Your name is", name)

                          Output

                       Enter your name: Ankit
                       Your name is Ankit

     INPUT AND OUTPUT
                      RAPID RECALL                             Tick ( ) if you know this.
     Python provides built-in functions to interact with users and handle input and output operations.
                         1.  The print() function is used to display output on the screen in Python.
     THE INPUT( ) FUNCTION

     The input() function is used to take input from the user. It reads a line of text entered by the user,   2.  The input() function is used to take input from the user.
     which is then returned as a string.
     Syntax of input() function:

     input(<prompt>)
     Here, the prompt is the string or message you want to display on the screen.  CHARACTER SET
     For example:
                     A  character  set is  the  collection  of characters  a  programming  language  recognises.  Python
     name = input("Enter your name: ")  accepts all ASCII and Unicode characters, including:

     >>> Enter your name: Ankit    Letters of the alphabet: All capital letters (A-Z) and small letters (a-z).
     The text ‘Ankit’ entered by the user will be stored in the variable name.    Digits: All digits from 0 to 9.

                         Special symbols: Python supports a wide range of special symbols such as:
     THE PRINT( ) FUNCTION
                        " ' ; : ! ` ~ @ # $ % ^ & * ( ) _ + - = { } [ ]
     The print() function is used to display output on the screen in Python. It takes the specified text,
     variable or value and prints it in the Python shell or terminal.    White spaces: White spaces like tab space, blank space, newline (\n) and carriage return (\r).

                                                                                                                      91
                                                                                                  Python–Start to Code

| 88 89 90 91 92 93 94 95 96 97 98 |