fmt.Printf %* 格式化输出映射表

lily1110 · 2018-03-07 15:22:05 · 2674 次点击 · 大约8小时之前 开始浏览    置顶
这是一个创建于 2018-03-07 15:22:05 的主题,其中的信息可能已经有所发展或是发生改变。

%d : decimal integer

%x %o %b : integer in hexadecimal(十六进制) octal(八进制) binaery(二进制)

%f %g %e:floating-point number: 3.141593 3.141592653589793 3.141593e+00

%t: boolean:true or false

%c: rune(Unicode code point)

%s: string

%q: quoted string "abc" or rune 'c'

%v: any value in a natural format

%T: type of any value

fmt.Printf("%d %d\n", 1, 'c')
fmt.Printf("%x %o %b \n", 31, 31, 31)
fmt.Printf("%f %g %e \n", 3.141592653589793238462643383249901429, 3.141592653589793238462643383249901429, 3.141592653589793238462643383249901429)
fmt.Printf("%t %t \n", true, false)
fmt.Printf("%c %s\n", 'd', "d")
fmt.Printf("%q %q %q \n", "abcd", "c", 'c')
fmt.Printf("%v %v %v\n", symbol1, "abcd", 'c')
fmt.Printf("%T %T %T\n", symbol1, "abcd", 'c')

对应的输出为

1 99

1f 37 11111

3.141593 3.141592653589793 3.141593e+00

true false

d d

"abcd" "c" 'c'

[usd eur ¥] abcd 99

[3]string string int32


有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

2674 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传