The println! Macro
A free lesson from Swipe Coding · Rust, level 2 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
println! prints text to the screen, followed by a newline. Notice the exclamation point at the end of its name: that ! means println! is a macro, not an ordinary function. Macros are expanded into other code at compile time, which is how println! can safely check that your format string matches the values you passed it before the program even runs — a plain function couldn't do that.
fn main() {
println!("Hello, world!");
}You can insert values into the printed text using curly-brace placeholders: {}. Each {} in the format string is filled in, in order, by the extra arguments you pass after it, separated by commas.
let name = "Maya";
let age = 21;
println!("{} is {} years old", name, age);
// Maya is 21 years oldThe ! at the end of println! signals that it's a ____ rather than an ordinary function.
Rust also has print!, which works exactly like println! but doesn't add a trailing newline, so the next thing printed continues on the same line. There's also format!, which builds and returns a String instead of printing anything — handy when you want the formatted text for later instead of showing it right away.
What does println!("{} scored {}", "Sam", 90) print?
println!("{} scored {}", "Sam", 90);Keep your streak going in Swipe Coding
Swipe through every level of Rust on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.
Get the Swipe apps →