fmt.Printf
var ch int = '\u0041'
var ch2 int = '\u03B2'
var ch3 int = '\U00101234'
fmt.Printf("%d - %d - %d\n", ch, ch2, ch3) // integer
fmt.Printf("%c - %c - %c\n", ch, ch2, ch3) // character
fmt.Printf("%X - %X - %X\n", ch, ch2, ch3) // UTF-8 bytes
fmt.Printf("%U - %U - %U", ch, ch2, ch3) // UTF-8 code point
fmt.Printf("%T", i12) // 查看i12的数据类型
格式化说明符 %c
用于表示字符;当和字符配合使用时,%v
或 %d
会输出用于表示该字符的整数;%U
输出格式为 U+hhhh 的字符串
输出完整类型实例
%#v
package main
import (
"fmt"
"strconv"
)
type TwoInts struct {
a int
b int
}
func (tn *TwoInts) String() string {
return strconv.Itoa(tn.a) + "/" + strconv.Itoa(tn.b)
}
func main() {
two1 := new(TwoInts)
two1.a = 12
two1.b = 22
fmt.Printf("%v\n", two1)
fmt.Printf("%T\n", two1)
fmt.Printf("%#v\n", two1)
}
12/22
*main.TwoInts
&main.TwoInts{a:12, b:22}