Exerpad
🔥 1
10 XP
Lesson · Chapter: Print+10 XP for reading

What is Print?

The println!() macro is how your Rust program talks to you! It displays text on the screen.

Printing Text

To print text, put it inside quotes and wrap it with println!():

rust
fn main() {
println!("Hello!");
}
Output
Press Run to see the output.

This shows:

Hello!

Notice the ! after println -- that means it's a macro, which is a special kind of command in Rust. Don't forget it!

Printing Numbers

You can print numbers by using {} as a placeholder:

rust
fn main() {
println!("{}", 42);
println!("{}", 3.14);
}
Output
Press Run to see the output.

Printing Multiple Things

Use multiple {} placeholders to print several things on one line:

rust
fn main() {
println!("I am {} years old", 10);
}
Output
Press Run to see the output.

Output:

I am 10 years old

You can use as many placeholders as you want:

rust
fn main() {
println!("{} + {} = {}", 2, 3, 5);
}
Output
Press Run to see the output.

Output:

2 + 3 = 5

Multiple Lines

Each println!() starts a new line:

rust
fn main() {
println!("Line 1");
println!("Line 2");
println!("Line 3");
}
Output
Press Run to see the output.

Blank Lines

Call println!() with nothing inside the quotes to print a blank line:

rust
fn main() {
println!("Top");
println!();
println!("Bottom");
}
Output
Press Run to see the output.

Output:

Top

Bottom

Now let's practice!