-
Notifications
You must be signed in to change notification settings - Fork 1
/
fmt-print.go
77 lines (68 loc) · 2.15 KB
/
fmt-print.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// https://medium.com/rungo/string-formatting-in-go-dd752ff7f60
package main
import "fmt"
func main() {
b := true
i := 123
f := 987.654
c := 3 + 7i
str := "text"
arr := []int{1, 2, 3}
m := map[string]int{"one": 1, "two": 2}
s := struct {
name string
age int
}{"John", 26}
fmt.Print("Standard Print with manual newline \n")
fmt.Print("1", 2, true, 3, 4, nil, "\n")
fmt.Print("\n")
fmt.Println("Standard Print with auto newline")
fmt.Println("1", 2, true, 3, 4, nil)
fmt.Println()
fmt.Printf("String interpolation \n")
fmt.Printf("%%v - default format in golang \n")
fmt.Printf("%v \n", b) // boolean
fmt.Printf("%v \n", i) // integer
fmt.Printf("%v \n", f) // float
fmt.Printf("%v \n", c) // complex number
fmt.Printf("%v \n", str) // string
fmt.Printf("%v \n", arr) // array
fmt.Printf("%v \n", m) // map
fmt.Printf("%v \n", s) // struct
fmt.Printf("%v \n", c) // channel
fmt.Printf("%v \n", &s) // pointer
fmt.Printf("\n")
fmt.Printf("String interpolation \n")
fmt.Printf("%%#v - syntax representation \n")
fmt.Printf("%#v \n", b) // boolean
fmt.Printf("%#v \n", i) // integer
fmt.Printf("%#v \n", f) // float
fmt.Printf("%#v \n", c) // complex number
fmt.Printf("%#v \n", str) // string
fmt.Printf("%#v \n", arr) // array
fmt.Printf("%#v \n", m) // map
fmt.Printf("%#v \n", s) // struct
fmt.Printf("%#v \n", c) // channel
fmt.Printf("%#v \n", &s) // pointer
fmt.Printf("\n")
fmt.Printf("String interpolation \n")
fmt.Printf("%%T - type format \n")
fmt.Printf("%T \n", b) // boolean
fmt.Printf("%T \n", i) // integer
fmt.Printf("%T \n", f) // float
fmt.Printf("%T \n", c) // complex number
fmt.Printf("%T \n", str) // string
fmt.Printf("%T \n", arr) // array
fmt.Printf("%T \n", m) // map
fmt.Printf("%T \n", s) // struct
fmt.Printf("%T \n", c) // channel
fmt.Printf("%T \n", &s) // pointer
fmt.Printf("\n")
fmt.Printf("String interpolation \n")
fmt.Printf("%%d - base10 format \n")
fmt.Printf("%%b - base2 format \n")
fmt.Printf("%%0 - base8 format \n")
fmt.Printf("%%h - base16 format \n")
fmt.Printf("%%f - decimal format \n")
fmt.Printf("%%e - scientific notation format \n")
}