go 格式化占位符

package main
import "fmt"
func main(){
  %v,原样输出
			%T,打印类型
			%t,bool类型
			%s,字符串
			%f,浮点
			%d,10进制的整数
			%b,2进制的整数
			%o,8进制
			%x,%X,16进制
				%x:0-9,a-f
				%X:0-9,A-F
			%c,打印字符
			%p,打印地址

}

  

package main

import (
	"fmt"
)

func main() {
	a := 100           //int
	b := 3.14          //float64
	c := true          // bool
	d := "Hello World" //string
	e := `Ruby`        //string
	f := 'A'           //asin码 
	fmt.Printf("%T,%b
", a, a)
	fmt.Printf("%T,%f
", b, b)
	fmt.Printf("%T,%t
", c, c)
	fmt.Printf("%T,%s
", d, d)
	fmt.Printf("%T,%s
", e, e)
	fmt.Printf("%T,%d,%c
", f, f, f)
	fmt.Println("-----------------------")
	fmt.Printf("%v
", a)
	fmt.Printf("%v
", b)
	fmt.Printf("%v
", c)
	fmt.Printf("%v
", d)
	fmt.Printf("%v
", e)
	fmt.Printf("%v
", f)

}

  

打印结果:
int,1100100
float64,3.140000
bool,true
string,Hello World
string,Ruby
int32,65,A
-----------------------
100
3.14
true
Hello World
Ruby
65

  

原文地址:https://www.cnblogs.com/kevin-yang123/p/15180993.html