Python Variables, Mutability & Shadowing
In Rust, variables are immutable by default. To allow reassignment, you must explicitly declare the variable with the mut keyword. Shadowing allows re-declaring a variable with let to transform types cleanly.
"In Rust, a variable without mut is like stone carving—once engraved, it cannot be altered. Adding mut is like using an erasable whiteboard."
Deep Dive: How It Works
Immutable by Default: Prevents unintended state mutations across large concurrent codebases.
mut Keyword: let mut count = 0; explicitly marks intent to mutate.
Shadowing: let x = 5; let x = x + 1; creates a new variable reusing the same identifier, allowing type transformation.
Syntax Blueprint
let x = 5; (Immutable) | let mut y = 10; y = 20; (Mutable)
Use let for read-only values, mut for values that change, and shadowing for type changes.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Reassigning an immutable variable.Why it happens: let x = 5; x = 6; causes compiler error E0384: cannot assign twice to immutable variable.
How to fix: Declare with let mut x = 5; if reassignment is intentional.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Update mutable counter
Declare let mut energy = 100;
Subtract 30 from energy (energy -= 30);
Print "Remaining Energy: 70".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.