Advanced Programming with Python
🧠 Based on CERN's Python Advanced Course
🗂 Table of Contents
1. Introduction
2. Variables
3. Basic Types
4. Containers
5. Functions
6. Exception Handling
7. Topics Mentioned But Not Covered
📌 1. Introduction
Begins with a simple Hello World example.
Introduces the Zen of Python by Tim Peters:
“Readability counts.”
“Simple is better than complex.”
“There should be one—and preferably only one—obvious way to do it.”
🧮 2. Variables
Variables are references to objects (not containers of data).
Example of reassignment:
x = 3
y = x
x = 2 # y stays as 3
Conditional assignment using if and inline expressions:
label = 'Pos' if x > 0 else 'Neg'
🔤 3. Basic Types
➤ Strings
Strings are immutable, iterable, and support many built-in methods.
Examples: .replace(), .upper(), .format(), and f-strings.
➤ Enums
Used to define sets of named constants:
from enum import Enum
class Action(Enum):
SAVE = 1
LOAD = 2
📦 4. Containers
➤ Lists
Mutable, ordered collections.
Features: append, extend, slice, and sort with keys and reverse.
➤ Tuples
Like lists but immutable — great for fixed structures.
➤ Sets
Unordered collections with unique elements.
Support operations like union, intersection, difference.
➤ Dictionaries
Key-value pairs with fast lookup.
Common operations: .items(), .get(), and dictionary comprehensions.
🔧 5. Functions
➤ Arguments
Use of default values, *args, **kwargs, and keyword-only arguments.
➤ Recursion
Classic example:
def factorial(n):
return n * factorial(n-1) if n > 1 else 1
➤ Memoization
Improves performance by caching results.
➤ Decorators
Wrap functions to modify behavior without altering core logic.
➤ Context Managers
Using with statements for safe resource handling.
🚨 6. Exception Handling
Encourages handling errors gracefully with try/except/finally.
Promotes “asking forgiveness over permission” — Python’s error-handling philosophy.
📘 7. Topics Mentioned But Not Detailed
Object-Oriented Programming
Packaging
Documentation
Unit Testing
Continuous Integration
📎 Based on: Advanced_Programming_with_Python[1].pdf