fmt.Printf

  1. var ch int = '\u0041'
  2. var ch2 int = '\u03B2'
  3. var ch3 int = '\U00101234'
  4. fmt.Printf("%d - %d - %d\n", ch, ch2, ch3) // integer
  5. fmt.Printf("%c - %c - %c\n", ch, ch2, ch3) // character
  6. fmt.Printf("%X - %X - %X\n", ch, ch2, ch3) // UTF-8 bytes
  7. fmt.Printf("%U - %U - %U", ch, ch2, ch3) // UTF-8 code point
  8. fmt.Printf("%T", i12) // 查看i12的数据类型

格式化说明符 %c 用于表示字符;当和字符配合使用时,%v%d 会输出用于表示该字符的整数;%U 输出格式为 U+hhhh 的字符串

输出完整类型实例

%#v

  1. package main
  2. import (
  3. "fmt"
  4. "strconv"
  5. )
  6. type TwoInts struct {
  7. a int
  8. b int
  9. }
  10. func (tn *TwoInts) String() string {
  11. return strconv.Itoa(tn.a) + "/" + strconv.Itoa(tn.b)
  12. }
  13. func main() {
  14. two1 := new(TwoInts)
  15. two1.a = 12
  16. two1.b = 22
  17. fmt.Printf("%v\n", two1)
  18. fmt.Printf("%T\n", two1)
  19. fmt.Printf("%#v\n", two1)
  20. }
  21. 12/22
  22. *main.TwoInts
  23. &main.TwoInts{a:12, b:22}