fmt verbs in Go
The verb decides the rendering: value, quoted, type, or Go syntax.
type Run struct {
Lang string
TPM float64
}
func verbs() []string {
run := Run{Lang: "go", TPM: 104.567}
return []string{
fmt.Sprintf("%v", run),
fmt.Sprintf("%+v", run),
fmt.Sprintf("%#v", run),
fmt.Sprintf("%T", run),
fmt.Sprintf("%q|%8.2f|%-8s|", run.Lang, run.TPM, run.Lang),
fmt.Sprintf("%d %05d %x %b", 42, 42, 255, 5),
}
}
How it works
%vis the default,%+vadds struct field names.%qquotes,%Tprints the type,%#vprints Go syntax.- Width and precision go between the percent and the verb.
Keywords and builtins used here
float64funcreturnstringstructtype
The run, in numbers
- Lines
- 16
- Characters to type
- 331
- Tokens
- 106
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 67 seconds.
Step 4 of 5 in Strings & formatting, step 28 of 30 in Language basics.