Page 420 - ComputerScience_Class_11
P. 420

For example, to run a Python program line by line, the interpreter executes each statement in order.
                   Program.py

                File  Edit  Format   Run   Options   Window    Help

                  print("Hello")
                  print(10 + 5)
                  print("Python")



                   Output

                  Hello
                  15
                  Python



              Each line is executed one after another by the interpreter.

              Advantages of Interpreter-Based Python are:
              •  No need to compile the program before running

              •  Errors are easy to find and fix
              •  Faster program testing

              •  Beginner-friendly
              Note: All the examples stated above will be explained further.


                  12.6 PYTHON CODE EXECUTION
              Python follows an interpretation model with bytecode compilation, not a purely traditional compiled model. In which
              the source code you write is first translated into bytecode. This bytecode is then executed by the Python Virtual
              Machine (PVM). In simple terms, Python source code compiles your code into bytecode and then interprets it during
              execution.
              There are two modes for using the Python interpreter:

              •  Interactive Mode
              •  Script Mode

              12.6.1 Running Python in interactive mode
              Python allows you to run code directly at the interactive prompt without providing a script file to the interpreter. To
              open Python IDLE - Click Start -> Then IDLE (Python 3.13 64 Bit).
              Once you’re inside the Python interpreter, you can start typing commands.


              >>> print("hello world")
                  hello world
              # Relevant output is displayed on subsequent lines without the >>> symbol

              >>> x=[0,1,2]





                  418  Touchpad Computer Science (Ver. 3.0)-XI
   415   416   417   418   419   420   421   422   423   424   425