Immutable bindings with let
Quick answer
let introduces a binding: a name associated with a value. Rust bindings are immutable by default, so an ordinary let binding cannot be reassigned. Give a value a meaningful name and use it in later calculations.
Name values once
The syntax let name = value; creates a local binding. The compiler often determines its type from the value and later usage. Use lowercase names with underscores between words; this is a naming convention. Immutability of a binding is not a promise that every reachable object is immutable.
Expected stdout (not executed):
Books: 12The value can be read using its name.
fn main() { let price = 4; let quantity = 3; let total = price * quantity; println!("Total: {total}");}Expected stdout (not executed):
Total: 12The name total represents the calculated value; named placeholders are supported in the course baseline.
Common mistake
Writing books = 13; after let books = 12; is not allowed. Use a new name for a derived result or learn mut in the next lesson.
Try it yourself
Define the number of boxes and items per box, calculate the total, and print it.
Static examples for Rust 1.85.0, edition 2024. Run them locally in a disposable project; ByteMind execution support and these outputs have not been verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Immutable bindings with let — practice quiz
Choose one answer per question, then review the explanation.
After `let apples = 6; let total = apples + 4;`, what is total?
Which name follows the lesson's customary Rust style for a count?
Why use `let width = 8;` rather than `let mut width = 8;` when width never changes?