Python Interpreter
1
There are two ways to use the interpreter
❑ Interactive mode
❑ Script mode
1.Interactive mode
❑ In interactive mode python code can be directly typed and the interpreter
displays the result(s) immediately.
❑ It is a command shell which give immediate feedback for each
statement.
❑ Working in interactive mode is convenient for beginners and for testing
small pieces of code
❑ The following command can be used to invoke Python IDLE from
Windows OS.
Start → All Programs → Python 3.x → IDLE (Python 3.x)
Python Interpreter
2
Python Interpreter
3
❑ The first three lines are the information about python version number and
operating system.
❑ The last line >>> is a prompt (chevron) that indicates that the interpreter is
ready to enter code.
❑ If the user types a line of code and hits enter the interpreter displays the
result.
❑ Drawback:
❑ We cannot save the statements and have to retype all the statements once
again to re-run them.
Python Interpreter
4
Python Interpreter
5
Python Interpreter
6
2.Script mode
❑ Basically a script is a text file containing python statements.
❑ Scripts are saved to disk for future use.
❑ Python scripts have the extension .py, meaning that the filename ends
with .py
Creating Scripts in Python
1. Choose File → New File or press Ctrl + N in Python shell window.
Interactive VS Script mode
7
INTERACTIVE MODE SCRIPT MODE
A way of using the Python
interpreter by typing commands
and expressions at the prompt
A way of using the Python interpreter
to read and execute statements in a
script
Can’t save and edit the code Can save and edit the code
We can see the results
immediately
We cannot see the results
immediately

1.2 Python Interpreter and Interactive Modes(1).pptx

  • 1.
    Python Interpreter 1 There aretwo ways to use the interpreter ❑ Interactive mode ❑ Script mode 1.Interactive mode ❑ In interactive mode python code can be directly typed and the interpreter displays the result(s) immediately. ❑ It is a command shell which give immediate feedback for each statement. ❑ Working in interactive mode is convenient for beginners and for testing small pieces of code ❑ The following command can be used to invoke Python IDLE from Windows OS. Start → All Programs → Python 3.x → IDLE (Python 3.x)
  • 2.
  • 3.
    Python Interpreter 3 ❑ Thefirst three lines are the information about python version number and operating system. ❑ The last line >>> is a prompt (chevron) that indicates that the interpreter is ready to enter code. ❑ If the user types a line of code and hits enter the interpreter displays the result. ❑ Drawback: ❑ We cannot save the statements and have to retype all the statements once again to re-run them.
  • 4.
  • 5.
  • 6.
    Python Interpreter 6 2.Script mode ❑Basically a script is a text file containing python statements. ❑ Scripts are saved to disk for future use. ❑ Python scripts have the extension .py, meaning that the filename ends with .py Creating Scripts in Python 1. Choose File → New File or press Ctrl + N in Python shell window.
  • 7.
    Interactive VS Scriptmode 7 INTERACTIVE MODE SCRIPT MODE A way of using the Python interpreter by typing commands and expressions at the prompt A way of using the Python interpreter to read and execute statements in a script Can’t save and edit the code Can save and edit the code We can see the results immediately We cannot see the results immediately