keyword

Rust let: bind a name to a value

Use `let` to introduce a local binding. The name gives you a way to refer to a value later. The compiler can infer its type from the expression. Expected output: 3 Why: The name tickets refers to the integer 3. Common mistake: A binding introduced without mut cannot be assigned a second value after initialization.

Formal Syntax & Structure

rust syntaxrust
let name = expression;

Working Example

Example Snippetrust
fn main() {    let tickets = 3;    println!("{tickets}");}
Rust Reference