Go · lesson 3 of 30 · First stepsPrint in columns
Printf fills a pattern: %s text, %d whole numbers, %.1f one digit after the point, %6.1f the same in six columns, %v any value.
03-printf.go Download 03-printf.go
package main
import "fmt"
func main() {
fmt.Printf("%-10s %6s\n", "volume", "TB")
fmt.Printf("%-10s %6.1f\n", "archive", 7.28)
fmt.Printf("%-10s %6.1f\n", "media", 14.55)
fmt.Printf("%d disks, %d%% full\n", 4, 75)
fmt.Printf("%v %T, %q\n", 8, 8, "a quoted text")
line := fmt.Sprintf("disk-%02d", 3)
fmt.Println(line)
}
Terminal
$ ./03-printf
volume TB
archive 7.3
media 14.6
4 disks, 75% full
8 int, "a quoted text"
disk-03Exercise
Add a third volume to the table.
TurboShell does not contain Go. These programs are made in Bucket & Code with its Go runtime; the finished file runs on the NAS without Go.