Los verbos de fmt en Go
El verbo decide cómo se muestra: valor, citado, tipo o sintaxis de Go.
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),
}
}
Cómo funciona
%ves el predeterminado;%+vagrega los nombres de campo del struct.%qentrecomilla,%Timprime el tipo,%#vimprime sintaxis de Go.- El ancho y la precisión van entre el porcentaje y el verbo.
Palabras clave y builtins usados aquí
float64funcreturnstringstructtype
El intento, en números
- Líneas
- 16
- Caracteres a escribir
- 331
- Tokens
- 106
- Ritmo de tres estrellas
- 95 tpm
Al ritmo de tres estrellas de 95 tokens por minuto, este intento toma unos 67 segundos.
Paso 4 de 5 en Cadenas y formato; paso 28 de 30 en Fundamentos del lenguaje.