Standard library / fmt

fmt.Stringer

String() supplies the default human-readable representation for relevant formatting verbs. Keep the implementation free of recursive formatting of the same receiver. Expected stdout: 'L7\n'.

Formal Syntax & Structure

go syntaxgo
type Stringer interface { String() string }

Working Example

Example Snippetgo
package main
import (  "fmt")
type label int
func (l label) String() string { return fmt.Sprintf("L%d", int(l)) }func main() {  fmt.Println(label(7))}
Go Reference