

After processing a bracketed expression, subsequent verbs will use arguments n+1, n+2, etc. The same notation before a '*' for a width or precision selects the argument index holding the value. However, the notation immediately before the verb indicates that the nth one-indexed argument is to be formatted instead.

In Printf, Sprintf, and Fprintf, the default behavior is for each formatting verb to format successive arguments passed in the call. When printing a struct, fmt cannot and therefore does not invoke formatting methods such as Error or String on unexported fields. Such pathologies are rare, however, and the package does not protect against them. Infinite recursion can also be triggered by self-referential data structures, such as a slice that contains itself as an element, if that type has a String method. Uint, uint8 etc.: %d, %#x if printed with %#vįor compound objects, the elements are printed using these rules, recursively, laid out like this: struct: Pointer: %p base 16 notation, with leading 0x %X base 16, upper-case, two characters per byte %x base 16, lower-case, two characters per byte %q a double-quoted string safely escaped with Go syntax String and slice of bytes (treated equivalently with these verbs): %s the uninterpreted bytes of the string or slice In the manner of strconv.FormatFloat with the 'b' format, %U Unicode format: U+1234 same as "U+%04X"įloating-point and complex constituents: %b decimalless scientific notation with exponent a power of two, %X base 16, with upper-case letters for A-F %x base 16, with lower-case letters for a-f %q a single-quoted character literal safely escaped with Go syntax.
#Newline mathmod code#
%c the character represented by the corresponding Unicode code point %% a literal percent sign consumes no value %T a Go-syntax representation of the type of the value %#v a Go-syntax representation of the value
#Newline mathmod plus#
When printing structs, the plus flag (%+v) adds field names General: %v the value in a default format The format 'verbs' are derived from C's but are simpler.

Package fmt implements formatted I/O with functions analogous to C's printf and scanf.
