Page 37 - Code & Click - 7
P. 37

Component                                           Description

             Python Interpreter     Displays  the  Python  command  prompt  >>>.  Commands  are  typed  at  the
             or Shell               prompt and their results are displayed below the commands.
             Status Bar             Displays the line number and column number at which the cursor is in the
                                    Interpreter.

             Editor                 Opens in Script mode. Displays the Script Area where code is typed.

            WORKING WITH PYTHON IDLE
            Let us quickly recap what you have learned about working in Python in the previous class.

            Python Working Modes
            The two working modes in which the Python IDLE works are:
              1.  Interactive Mode or Shell Mode : In the Interactive mode, each command is typed at the
                  prompt. When we press the Enter key, the Interpreter executes the command and displays the
                  result below the command. The commands are not saved and, hence, cannot be reused. The
                  Interactive mode can display text messages, results of calculations, and values of variables.
              2.  Script mode : The Script mode, also known as Batch Processing mode, lets you execute several
                  Python commands together in a sequence. This is done by saving the set of commands as a file
                  called a script or program. The saved script can be reused later as required. Once the script is
                  created, you can execute the script to view the output.

            Understanding Variables
            Variables are named locations in the memory of a computer where data is stored temporarily. The
            data stored in the variables can be manipulated during the execution of a program. Every variable in
            a script has a name by which it is referred to during the execution of the script. The rules for naming
            variables in Python are:
              1.  Variable names should be meaningful.
              2.  Variable names can contain alphabets, digits, and the underscore symbol ( _ ).
              3.  Variable names must start with an alphabet or the underscore symbol.
              4.  Reserved terms or keywords in Python cannot be used as a variable name.
              5.  Variable names in Python are case-sensitive.

            Print( ) Function
            The Print( ) function is used to display the value of a variable, an expression, or text messages on the
            screen. The syntax of the print( ) function is:
                   print(text message/variable name/expression)

            To display multiple values with the print( ) function, the values are separated by commas ( , ).
                   print(value1, value2, value3)


            Input( ) Function
            The Input( ) function is used to accept data from the user and store it in a variable. The syntax for
            the input( ) command is:
                   <variable name> = input(“Message to display”)


                                                                                                                 35
   32   33   34   35   36   37   38   39   40   41   42