Go Example--格式化字符串

package main

import (
	"fmt"
	"os"
)

type point struct {
	x, y int
}

func main() {
	p := point{1, 2}
	fmt.Printf("%v
", p)
	fmt.Printf("%+v
", p)
	fmt.Printf("%#v
", p)
	fmt.Printf("%T
", p)
	fmt.Printf("%t
", true)
	fmt.Printf("%d
", 123)
	fmt.Printf("%b
", 14)
	fmt.Printf("%c
", 33)
	fmt.Printf("%x
", 456)
	fmt.Printf("%f
", 78.9)
	fmt.Printf("%e
", 12340000.0)
	fmt.Printf("%E
", 12340000.0)
	fmt.Printf("%s
", ""string"")
	fmt.Printf("%q
", ""string"")
	fmt.Printf("%x
", "hex this")
	fmt.Printf("%p
", &p)
	fmt.Printf("|%6d|%6d|
", 12, 345)
	fmt.Printf("|%6.2f|%6.2f|
", 1.2, 3.45)
	fmt.Printf("|%-6.2f|%-6.2f|
", 1.2, 3.45)
	fmt.Printf("|%6s|%6s|
", "foo", "b")
	fmt.Printf("|%-6s|%-6s|
", "foo", "b")
	s := fmt.Sprintf("a %s", "string")
	fmt.Println(s)
	fmt.Fprintf(os.Stderr, "an %s
", "error")
}
原文地址:https://www.cnblogs.com/promenader/p/9858518.html