Memory-Management

17 articles
Interview Preparation Intermediate

6.15 Hands-on Exercises

Practice Programs Write a function demonstrating UnboundLocalError, then fix it using the global keyword. Given a nested list, show the …

Jan 20, 2026 Read more
Interview Preparation Intermediate

6.14 Interview Questions

Frequently Asked Questions What is the difference between a variable and an object in Python? Explain the difference between is and == with …

Jan 20, 2026 Read more
Interview Preparation Beginner

6.13 Best Practices

Meaningful Names Choose names that describe what a variable holds (user_count, not uc) — this is the single highest-leverage readability …

Jan 20, 2026 Read more
Interview Preparation Intermediate

6.12 Common Mistakes

UnboundLocalError What Goes Wrong? Referencing a variable inside a function before assigning it, when that same name is also assigned …

Jan 20, 2026 Read more
Interview Preparation Intermediate

6.11 Variables in DevOps

DevOps work is full of environment-specific values — variables, in every sense (Python, OS environment, and Terraform), are how …

Jan 20, 2026 Read more
Interview Preparation Intermediate

6.10 Variables in Functions

Passing Variables What Is It? Python passes arguments by “assignment” — the parameter name inside the function becomes a new …

Jan 20, 2026 Read more
Interview Preparation Beginner

6.9 Lifetime of Variables

Creation A variable’s lifetime begins the moment it’s first assigned a value. Usage A variable remains usable for as long as its …

Jan 20, 2026 Read more
Interview Preparation Intermediate

6.8 Variable Scope

flowchart TD B["Built-in\nlen, print, range, ... — always available"] Gs["Global\nnames at module level"] E["Enclosing\nnames in an outer …

Jan 20, 2026 Read more
Interview Preparation Intermediate

6.7 Memory Optimization

Object Reuse Where possible, CPython reuses existing immutable objects instead of allocating new ones for identical values. The two …

Jan 20, 2026 Read more
Interview Preparation Intermediate

6.6 Garbage Collection

Reference Counting What Is It? CPython’s primary memory-management mechanism, introduced in 5.12 Memory Representation — every object …

Jan 20, 2026 Read more
Interview Preparation Intermediate

6.5 Copying Objects

When shared references aren’t what you want (see 6.2 Objects and Variable References), Python offers three distinct ways to copy a …

Jan 20, 2026 Read more
Interview Preparation Intermediate

6.4 Assignment Operations

Reference Assignment b = a makes b point at the exact same object a does — no data is copied, as covered in 6.2 Objects and Variable …

Jan 20, 2026 Read more
Interview Preparation Intermediate

6.3 Memory Management: Stack vs Heap

Stack vs Heap What Is It? The stack holds function call frames — each frame stores its local variable names and the references they point …

Jan 20, 2026 Read more
Interview Preparation Beginner

6.2 Objects and Variable References

Objects, Briefly Every value a variable can refer to — numbers, strings, functions, even classes — is an object with its own identity, type, …

Jan 20, 2026 Read more
Interview Preparation Beginner

6.1 Introduction to Variables

flowchart TD V["Variable"] V --> R["References\nlabel, not a box"] V --> M["Stack vs Heap\nwhere things live"] V --> C["Copying\nshallow vs …

Jan 20, 2026 Read more