Python Programming Basics
DBATU Diploma Notes - PPT
Introduction to Python
Programming
• Python = High-level, interpreted, general-
purpose programming language
• Created by Guido van Rossum (1989), released
in 1991
• Philosophy = Code readability & simplicity
• Beginner friendly + Powerful for advanced
users
Features of Python
• Easy to Learn & Readable → Simple syntax like
English
• Interpreted Language → Executes line by line
• Object-Oriented → Supports classes, objects,
inheritance, polymorphism
• Cross-Platform → Runs on Windows, Linux,
Mac
• Extensive Libraries → NumPy, Pandas,
Matplotlib, etc.
Where is Python Used?
• AI & ML → TensorFlow, PyTorch
• Data Science → Pandas, NumPy, Matplotlib
• Web Development → Django, Flask
• Automation / Scripting → Repetitive tasks
automation
• Game Development → Pygame
• Cyber Security → Ethical hacking tools
• IoT & Embedded Systems → MicroPython,
Python Frameworks & Libraries
• Web Development → Django, Flask
• GUI → Tkinter, PyQt
• Data Science → NumPy, Pandas, Matplotlib
• AI/ML → TensorFlow, scikit-learn, PyTorch
Python Virtual Machine (PVM)
• Runtime engine that executes Python
bytecode
• Converts bytecode → machine code
• Components: Runtime Engine, Runtime
Environment
• Frozen Binaries → Python program bundled
with PVM for easy execution
Typical Python Program Structure
• Documentation (comments/docstrings)
• Import (modules/libraries)
• Global Section (constants, global vars)
• Class Section (class definitions)
• Subprograms (functions)
• Playground/Main (main logic)
Python Implementations &
Distributions
• Implementations: CPython, Jython,
IronPython, PyPy, Stackless, MicroPython
• Distributions: Anaconda, Canopy,
PythonAnywhere, WinPython
Internal Working of Python
• Python Source Code → Compiler → Bytecode
• Bytecode executed by Python Virtual Machine
(PVM)
• Interpreter inside PVM → Machine code
execution
Basic Building Blocks of Python
• Identifiers → Names for variables/functions
• Keywords → Predefined reserved words
• Variables → Store values (dynamically typed)
• Indentation → Defines code blocks (no braces
{})
• Comments → Single-line (#), Multi-line ("""
""")
Literals in Python
• Numeric → int, float, complex
• String → Single/double/triple quotes
• Boolean → True / False
• Special → None
• Collections → List, Tuple, Dict, Set literals
Data Types & String Operations
• Data Types: int, float, complex, bool, str, list,
tuple, dict, set
• String operations:
• Indexing → s[0]
• Slicing → s[1:4]
• Methods → split(), join(), upper(), lower()
Input and Output
• Input → input() function (always returns
string)
• Output → print() function with sep, end, file,
flush parameters
Operators in Python
• Arithmetic (+, -, *, /, %, //, **)
• Assignment (=, +=, -=, *=, etc.)
• Relational (==, !=, >, <, >=, <=)
• Logical (and, or, not)
• Bitwise (&, |, ^, ~, <<, >>)
• Identity (is, is not)
• Membership (in, not in)
• Operator precedence & associativity define
Small Python Programs
• Square root of number → num ** 0.5
• Area of rectangle → l * b
• Area & Perimeter of square → a*a, 4*a
• Surface area & volume of cylinder → 2πrh +
2πr², πr²h
• Swap two variables → x, y = y, x