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\n", a, a)
	fmt.Printf("%T,%f\n", b, b)
	fmt.Printf("%T,%t\n", c, c)
	fmt.Printf("%T,%s\n", d, d)
	fmt.Printf("%T,%s\n", e, e)
	fmt.Printf("%T,%d,%c\n", f, f, f)
	fmt.Println("-----------------------")
	fmt.Printf("%v\n", a)
	fmt.Printf("%v\n", b)
	fmt.Printf("%v\n", c)
	fmt.Printf("%v\n", d)
	fmt.Printf("%v\n", e)
	fmt.Printf("%v\n", f)

}

  

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

  

posted on 2021-08-24 16:34  kevin_yang123  阅读(92)  评论(0编辑  收藏  举报