What is python
Python is an interpreted, Object oriented high level programming language with dynamic
semantics. Python syntax are easy compared to other languages.
Python is an interpreted, object oriented ,high level ,general-purpose programming language
with dynamic semantics that is widely used for scripting and automation.
Compiler vs interpreter
A compiler takes the entire source code translates it into machine code (or an
intermediate file) produces an executable before running.
An interpreter reads one statement at a time translates it line by line executes it
immediately
working
Python Source (.py)
↓
Bytecode Compiler
↓
Bytecode (.pyc)
↓
Python Virtual Machine (Interpreter)
↓
Execution
Step-by-step:
Python first compiles source code into bytecode.
Bytecode is not machine code.
The interpreter (PVM) executes the bytecode instruction by instruction.
Python virtual machine
Python Virtual Machine (PVM) is the runtime engine of Python. It is the part of Python that
executes Python bytecode.
Python is a high-level, platform-independent language. Different computers have different CPUs
and machine instructions.
Instead of generating machine code for every processor, Python does this:
Python source code (.py)
↓
Bytecode (.pyc)
↓
Python Virtual Machine
↓
Actual machine execution
Bytecode
Python first compiles the code into bytecode.
Bytecode is:
• Low-level
• Platform-independent
• Not machine code
Bytecode is stored in memory (temporary) or .pyc files inside __pycache__ directory
Continued….
Now the PVM takes over.
• Reads bytecode
• Executes one instruction at a time
• Uses a stack-based architecture
• Manages memory, objects, and garbage collection
• This is why Python is often called: Interpreted at runtime, compiled
internally.
• Postfix expression: (A+B)*C-> AB+C*
• Symbol Stack Postfix
Expression notation
Infix: Used by humans
Postfix(Reverse polish notation): Used by computers for evaluation
Prefix: Used in some functional languages
Best for computation: Postfix (stack-based)
Virtual machine
Virtual machines like PVM and JVM use stack-based architecture, while real processors
and some VMs like ARM, x86, and Lua VM use register-based architecture.
VM → Stack-based
CPU → Register-based
(Except a few smart VMs like Lua )
Lua Virtual Machine (Lua VM) is register-based, not stack-based.
Python source code (.py) is first compiled by the Python compiler.
This compilation produces bytecode (.pyc).
The Python Virtual Machine (PVM) then interprets and executes the bytecode, instruction by
instruction.
Is PVM a Real Machine?
It is software, written mainly in C (for CPython).
Examples of Python virtual machines:
CPython → PVM
Jython → JVM
IronPython → .NET CLR
Why python is platform
independent
Because:
Bytecode is same everywhere
Only the PVM implementation is platform-specific
So:
Windows → Windows PVM
Linux → Linux PVM
macOS → macOS PVM
Your .py file remains unchanged.
Important Points to Remember
Python Virtual Machine executes bytecode, not source code
Bytecode is not machine code
PVM is part of the Python interpreter
Python is compiled + interpreted
PVM provides portability and simplicity
That’s why Python is called an interpreted language, even though compilation happens internally.
Bytecode based language is python and Java.
Object oriented program: It is based on Class and object.
You can write program like structural and modular way also.
High level program: human understandable language(alphabet, numeric).
A high-level language is a programming language that is easy for humans to read, write, and
understand, because it uses English-like words and simple syntax, instead of hardware-
specific instructions.
In simple words
A high-level language lets programmers focus on logic and problem-solving, not on how the
CPU or memory works internally.
Dynamic semantic: Python get to know what is stored in variable at run time.
In python, only indentation and wide space should be managed.
History of python
Python is introduced by Guido Van Rossum in 1989.
First version of python released in 1991.
In 1994, python 1.0 was released with new feature which map, filter, lambda.
Python2.X also add some more feature like Comprehensions, garbage collection system.
After Python2.X, Python3.X released in 2008.
Features of python
1. Easy to learn and implement.
2. Open Source
Broad Standard library.
Cross platform.
Python Standard library
These come pre-installed with Python:
os, sys
math, random
datetime
json, csv
sqlite3
threading, multiprocessing
Numpy & Pandas
NOT part of Python standard library
Third-party libraries
Must be installed separately using pip
pip install numpy pandas
What kind of libraries are NumPy
& Pandas?
NumPy
Numerical computing library
Fast array operations, matrices, linear algebra
Used in scientific computing, ML, AI
Pandas
Data analysis & data manipulation library
Works with tables (DataFrame, Series)
Used in data science, analytics
NumPy and Pandas are third-party scientific libraries, not part of Python’s standard library,
but they extend Python’s capabilities for numerical computation and data analysis.
Features of python
• Work on interpreter logic.
• Multi-paradigm language.(You can use this language in multiple ways LIKE OOPS concept,
Structural programming language, or Simple way).
• High Level programming.
• Extendable Language.(You can combine python with other language also. And run it)
• Expressive Programming Language.
• GUI Programming Support.
Application of python:
• Network Programming
• Data Analysis
• Robotics
• Website Application & Application development(Django framework)
• Desktop Application(tinker library)
• Games Development.
• Web scraping
• Data visualization
• Scientific calculation (Numpy)
• Machine Learning & Artificial intelligence
• 3D Application development
• Audio & Videos Software development(VLC player based on python)
Companies using python:
Google
Youtube(it make better recommend system)
Facebook(Handle large data)
Quora(To make good readability)
Netflix (manage buffering)
NASA(Scientific calculation)
Instagram(To make better processing of image and video)
Torrent (Make better peer to peer connection)
Assessment
1. What is Python bytecode?
2. When is bytecode generated in Python?
3. Is Python bytecode platform-dependent?
4. Where is Python bytecode stored?
5. What is Python Virtual Machine (PVM)?
6. Is PVM a real hardware machine?
7. What is the main role of PVM?
8. Does Python use a stack-based or register-based virtual machine?
9. What is the difference between bytecode and machine code?
10. Explain the execution flow from Python source code to output.