Skip to content
Justice Tech School

println! and Formatting

println! uses {} for Display and {:?} for Debug. Add width, precision and named args.

Example
fn main() {
    let name = "Ada";
    println!("{name} is {}", 30);
    println!("{:>6}|{:<6}|{:^6}|", "r", "l", "c");
    println!("{:.2} {:05} {:#x} {:?}", 3.14159, 42, 255, "q");
}

Result

Ada is 30
     r|l     |  c   |
3.14 00042 0xff "q"

Exercise

Debug print.

println!("{}", v)

Quiz Test

What does {:?} print?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.