Hello Bar - Printf
- Printf
- %s
When printing values of variables it might be better to use the Printf function than the Println as the former allows us to use placeholders
such as %s
and be more precise where we would want to put a space and where don't.
These formatting placeholders are similar to what we have in other programming languages, but Go has a few additional placeholders.
Specifically %s
isn't special. It stands for strings.
package main
import (
"fmt"
)
func main() {
name := "Bar"
fmt.Printf("Hello %s\n", name)
}
Hello Bar