Tsallaka zuwa abun ciki
Justice Tech School

Printf Formatting

Verbs: %v any value, %d int, %s string, %f float, %q quoted, %T type, %5.2f width and precision.

Example
package main

import "fmt"

func main() {
	name, age := "Ada", 30
	fmt.Printf("%s is %d\n", name, age)
	fmt.Printf("%5.2f|%-5d|%05d|%T|%q\n", 3.14159, 42, 42, age, name)
}

Result

Ada is 30
 3.14|42   |00042|int|"Ada"

Exercise

Print the type.

fmt.Printf("%", x)

Quiz Test

What does %v print?

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