Go语⾔——字符串、数据的格式化输出(Printf)直接看代码:
//字符串输出
var sayHi string = "hello world"
fmt.Println(sayHi)
// \ 转义
fmt.Println("hello \nworld")
printf怎么输出字符fmt.Println("hello \"world")
// ` 可以将字符串按设定格式输出
fmt.Println(`hello "world`)
//浮点类型格式输出
var pi = 3.1
fmt.Printf("%f \n",pi);
//保留两位⼩数
fmt.Printf("%.2f \n",pi)
var age = 30
//整数 %d
fmt.Printf("my sge is %d \n",age)
//输出整数的⼆进制值
fmt.Printf("30`s binary %b \n",age)
//输出整数的⼋进制值
fmt.Printf("30`s octal %o \n",age)
//输出整数的⼗六进制值
fmt.Printf("30`s hex %x \n",age)
//格式化输出布尔类型
var married = true
fmt.Printf("is married %t \n",married)
//字符串输出
var sayHi = "hi"
fmt.Printf("he say '%s' \n",sayHi)
//输出变量类型
fmt.Printf("'age' type is %t \n",age)
fmt.Printf("'married1111' type is %t \n",married)
fmt.Printf("'married2222' type is %T \n",married)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。