Python
By reading these notes, you will gain knowledge tailored to your role, whether you are a beginner or practitioner focusing on Python Programming foundations.
Note – This page contains a complete summary of the topics. To learn more about each topic, click on the (
Expand), Topic-Heading, Image, or ‘Click Here’ hyperlink.
Before reading this document, please read Programming Basics & Foundations
Python is high level, interpreted, object oriented, high-level programming language with dynamic semantics. It is used everywhere: Scripting, Application development, websites to Artificial Intelligence and Data Science.
11 Python Foundation
| Topic | Key Concepts | Notes | Official Documentation Link |
| Python Basics | Variables, Memory, Data Types | Variables: – A name given to a memory location to store data (x = 10).Memory: – Variables are tags pointing to objects in memory. Data Types: – str (Text), int (Number), float (Decimal), bool (True/False). | Python Tutorial |
| Operators | Arithmetic, Logical, Comparison | • // is floor division (drops decimal).• ** is power ($2^3$).• is compares memory identity, == compares value.• Code: if x > 5 and y < 10: | Operators |
| Control Flow | Conditionals, Loops | • Indentation is mandatory. • range(start, stop, step).• break exits loop; continue skips to next iteration.• Code: for i in range(5): print(i) | Control Flow |
| Strings (Advanced) | Slicing, f-strings, Methods | • Strings are immutable. • Slicing: text[start:stop:step] → text[::-1] reverses string.• f-string: f"Hello {name}" is faster/cleaner.• strip(), split(), join(). | String Methods |
| Data Structures 1 | Lists & Tuples | • List: Mutable []. methods: append, pop, sort.• Tuple: Immutable (). Faster, keys for dicts.• Code: my_list = [1, 2, 3]; my_tuple = (1, 2) | Data Structures |
| Data Structures 2 | Dictionaries & Sets | • Dict: Key-Value {k:v}. O(1) lookup speed.• Set: Unique items {1, 2}. Great for removing duplicates.• Code: data.get("key", "default_val") avoids errors. | Dictionaries |
2. Functional and Modular Programming
| Topic | Key Concepts | Notes | Official Documentation Link |
| Functions | Scope, Return, Args | • def keyword.• *args: Tuple of unknown args.• **kwargs: Dict of unknown keyword args.• Docstrings: """Description""" for documentation.• Code: def add(*nums): return sum(nums) | Defining Functions |
| Functional Tools | Lambda, Map, Filter | • Lambda: One-line anonymous function. • Map: Apply function to all items. • Filter: Select items based on condition. • Code: squares = list(map(lambda x: x**2, numbers)) | Functional HOWTO |
| Comprehensions | List/Dict Comprehension | • Pythonic way to create lists. • More readable than for loops for simple logic.• Code: [x for x in range(10) if x % 2 == 0] | Comprehensions |
| Modules & Packages | Imports, __name__ | • Module: A .py file.• Package: A folder with __init__.py.• if __name__ == "__main__": ensures code runs only when executed directly, not when imported. | Modules |
| Virtual Environments | Isolation, Dependency Mgmt | • Crucial for every project. • Prevents library version conflicts. • Cmds: python -m venv venv, source venv/bin/activate (Linux), pip install -r requirements.txt. | venv |
3. Object Oriented Programming Python (OOP)
| Topic | Key Concepts | Notes | Official Documentation Link |
| Classes & Objects | Basics, self | • Class: Blueprint. Object: Instance. • self: Reference to the current instance.• __init__: Constructor method.• Code: class Dog: def __init__(self, name): self.name = name | Classes |
| Inheritance | Parent/Child, super() | • Don’t repeat code. Child inherits Parent’s methods. • super().__init__() calls parent constructor.• Polymorphism: Different classes, same method name. | Inheritance |
| Magic Methods | Dunder Methods | • Methods starting/ending with __.• __str__: User-friendly string representation.• __repr__: Developer debugging representation.• __len__, __add__. | Data Model |
| Advanced OOP | Decorators, Properties | • @property: Access methods like attributes (Getters).• @staticmethod: Function inside class not using self.• @classmethod: Uses cls (affects class state). | Built-in Functions |
4. Advanced Concepts
| Topic | Key Concepts | Notes | Official Documentation Link |
| Error Handling | Try, Except, Finally | • Never use bare except:. Catch specific errors.• finally: Runs cleanup code (closing files) always.• raise: Trigger custom errors.• Code: try: x/0 except ZeroDivisionError: print("Error") | Errors |
| File Handling | Read/Write, Context Mgr | • Always use with open(...) to auto-close files.• Modes: 'r' (read), 'w' (write/overwrite), 'a' (append).• Handling CSV and JSON is vital for data exchange. | Input/Output |
| Iterators & Generators | yield, Memory Efficiency | • Generator: Returns an iterator, pauses execution with yield.• Extremely memory efficient for large datasets. • Code: def gen(): yield 1; yield 2 | Generators |
| Decorators | Wrappers, @syntax | • Functions that modify other functions without changing their code. • Used for logging, authentication, timing. • Code: @login_required before a function definition. | Decorators |
| Concurrency | Threading vs AsyncIO | • Threading: I/O bound tasks (network calls). • Multiprocessing: CPU bound tasks (calculations). • AsyncIO: Modern async/await for high-performance I/O. • Code: async def main(): await func() | AsyncIO |
5. Libraries and Applications
| Topic | Key Concepts | Notes | Official Documentation Link |
| Standard Library | os, sys, datetime | • os: File paths, env variables (os.getenv).• sys: System arguments (sys.argv).• datetime: Date manipulation (datetime.now()). | Std Lib |
| Regex | Pattern Matching | • re module.• Find patterns (emails, phone numbers) in text. • \d (digit), \w (word char), + (one or more). | Regex |
| Web Development | Flask/FastAPI | • Flask: Micro-framework, easy for beginners. • Django: Full-stack, “batteries included”. • FastAPI: Modern, fast, for building APIs. | Flask |
| Data Science | Pandas, NumPy | • NumPy: Math & Matrix calculations. • Pandas: DataFrames (Excel for Python). • Matplotlib: Graphing & plotting. | Pandas |
6. Professional Skills
| Topic | Key Concepts | Notes | Official Documentation Link |
| Logging | logging vs print | • NEW TOPIC • print is for console; logging is for production.• Levels: DEBUG, INFO, WARNING, ERROR, CRITICAL. • Can save logs to file with timestamps. | Logging HOWTO |
| API Interaction | requests, JSON | • NEW TOPIC • Interacting with REST APIs. • r = requests.get(url).• data = r.json(). handling status codes (200, 404). | Requests Lib |
| Database Basics | SQL, SQLite | • NEW TOPIC • Storing data permanently. • Python has built-in sqlite3.• Basic syntax: SELECT, INSERT, CURSOR. | SQLite3 |
| Testing | Unit Tests, TDD | • unittest (built-in) or pytest (popular external).• Writing assertions to verify code works. • assert sum([1,2]) == 3. | Unittest |
| Security Best Practices | Safety, Validation | • NEW TOPIC (For DevSecOps) • Never use eval() or exec() on user input.• Use secrets module instead of random for passwords.• SQL Injection prevention (use parameterized queries). | Security Guide |
| Code Quality | PEP8, Linting | • NEW TOPIC • Style guide for Python Code. • Tools: flake8, black (formatter), mypy (type checking).• Type Hints: def add(x: int) -> int: | PEP 8 |