In addition to strings, we can also print numbers that are specified by {}
.
For example:
fn main() {
println!("{}", 123);
}
Output:
123
The numbers can be replaced with arithmetic expressions.
fn main() {
println!("{}", 2 + 4 * 3);
}
Output:
14
The expressions can be combined with a formatted text.
fn main() {
println!("{} x {} = {}", 14, 9, 14 * 9);
}
Output:
14 x 9 = 126
➡️ Next: Declaring Variables
📘 Back: Table of contents