0% found this document useful (0 votes)
13 views10 pages

Python Interpreter and Execution Basics

Uploaded by

shivshettianiket
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views10 pages

Python Interpreter and Execution Basics

Uploaded by

shivshettianiket
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

INTRODUCTION TO

PYTHON
Introducing the Python Interpreter, Program Execution, Execution Model Variations, The
Interactive Prompt, System Command Lines and Files
 INTRODUCING THE PYTHON
INTERPRETER

•A Python interpreter is a program that • Features of Python Interpreter


executes Python code line by line.
• Dynamic typing – No need to
•It translates human-readable Python code into declare variable types explicitly.
machine language so the computer can • Cross-platform – Works on
understand and run it. Windows, Linux, and macOS.
•Execution happens in real-time: as soon as one • Portable – The same code can
line is executed, the result is immediately run on different operating
displayed. systems.
• Readable syntax – Easy to write
and understand, similar to English.
 Modes of python Interpreter
[Link] Mode

•Code is written and executed directly in the Python shell (or terminal).
•Example:
>>> print("Hello") Hello
•Useful for testing small pieces of code and quick calculations.

[Link] Mode

• Code is written in a file with a “.py “extension and then executed.


• Example (in terminal):

python [Link]

•Used for larger programs and projects.


Python
interpreter
 PROGRAM EXECUTION IN
PYTHON
• Python code is written in .py file

• Source code is compiled into bytecode

• Bytecode is executed by the Python Virtual Machine (PVM)

• Output is displayed on the screen.

• Python executes code line by line (interpreted language)

• Source code (.py ) Bytecode(.pyc) PVM Output


 EXECUTION MODEL
VARIATIONS
• 1. Interactive ModeCode
• executed line by line in Python Shell / [Link] for quick testing.

• 2. Script Mode :
• Program saved in a .py [Link] using python [Link].
• Used for larger programs.

• 3. Compilation to Bytecode
• Source code → Bytecode (.pyc files).
• Executed by Python Virtual Machine (PVM).
 THE INTERACTIVE PROMPT IN
PYTHON
• 🔹 The Interactive Prompt in Python
• Also called Python Shell or REPL (Read–Eval–Print Loop)

• Opens when you type python in the terminal/command prompt

• Shows >>> symbol (primary prompt) for input

• Executes code line by line and displays output immediately

• Useful for testing, debugging, and experimenting with Python commands


 SYSTEM COMMAND LINES AND
FILES
• Python programs can be executed using system command lines
(Terminal / CMD).
• The command line allows running scripts with:
• python [Link]
• The sys module provides access to command-line arguments:
• [Link] → list of command-line arguments
• [Link][0] → script name
• [Link][1], [Link][2]... → arguments passed to the script
 Files in Python

Python provides built-in functions to handle files.

Basic file operations:


• open() → open a file
• read() / readline() / readlines() → read data
• write() / writelines() → write data
• close() → close the file

File modes:

"r" → Read
"w" → Write (overwrite)
"a" → Append
"b" → Binary
THANK
YOU

You might also like