println! is Rust’s standard macro for printing formatted output followed by a newline. The exclamation mark distinguishes it from an ordinary function call. Macros can reduce boilerplate and perform type detection so that different kinds of values can be printed. section 1.3.2 section 1.5
Use println! to:
- Print a fixed string, such as println!("Hello, world!"). section 1.3.2
- Insert a value with the {} placeholder, which uses a programmer-defined string representation. section 1.5
- Print values such as strings and other data types to standard output, or stdout. section 1.3.2 section 1.5
Printing several languages
fn greet_world() { println!("Hello, world!"); let regions = ["Grüß Gott!", "ハロー・ワールド"]; for region in regions.iter() { println!("{}", ®ion); } } This prints three lines, including UTF-8 strings in German and Japanese. section 1.3.2
Listing 1.1 “Hello World!” in three languages
fn greet_world() {
println!("Hello, world!"); #1
let southern_germany = "Grüß Gott!"; #2
let japan = "ハロー・ワールド"; #3
let regions = [southern_germany, japan]; #4
for region in regions.iter() { #5
println!("{}", ®ion); #6
}
}
fn main() {
greet_world(); #7
}
Inspect a complete greeting program showing fixed strings, a formatted placeholder, iteration, and the resulting output. section 1.3.2

