fmt format cheatsheet

go golang cheatsheet

This cheatsheet is a simplified list of all the verbs you can use in fmt methods that accept a format, such as fmt.Printf and fmt.Sprintf.

Numbers

  • %d - decimal integer
  • %x - hexadecimal integer
  • %o - octal integer
  • %b - binary integer
  • %f - float (3.141593)
  • %g - float (3.141592653589793)
  • %e - float (3.141593e+00)

Text

  • %s - string
  • %c - rune (Unicode code point)
  • %q - quoted string or rune (“string value”)

Misc

  • %t - boolean
  • %T - the type of any value
  • %% - percentage sign
  • %v - any value in a natural format