Search⌘ K

Variables

Explore how to create and use variables in Rust, including the distinction between strings and numbers. Understand basic operations and how the compiler helps catch errors, laying a foundation for effective Rust programming.

We'll cover the following...

Often, we don’t want to put all of the values we care about on one line like that. It can be more pleasant to define variables, which are convenient names that refer to the values we care about. We do that with let:

Rust 1.40.0
fn main() {
let name = "Michael";
println!("My name is {}", name);
}

Now, name is pointing at the string "Michael", and we can refer to that when we call println!. Variables are a core part of ...