Previously, we saw how to print multiple things on one line using placeholders, like:
println!("My favorite number is {}", 7)
Engagement Message
What was the exact output of that command?
Sometimes, we want to save a piece of information to use later in our program. Think of it like putting something in a labeled box so you can find it easily when you need it.
Engagement Message
Does that idea make sense?
In programming, these labeled boxes are called variables. We create a variable and give it a value using the let
keyword and the equals sign (=
).
For example:
let message = "Hello again!";
Here, message
is the variable name (the label on the box).
Engagement Message
What value did we store inside the message
variable?
Once you've stored something in a variable, you can use the variable's name wherever you would have used the value itself.
For instance:
Engagement Message
What do you think running these two lines would output?
