Last active
May 29, 2018 02:59
-
-
Save sekky0905/a444d3b53f774f6ad6645d3efdde63c1 to your computer and use it in GitHub Desktop.
忘れがちなGo言語の書式指定子を例付きでまとめた ref: http://qiita.com/Sekky0905/items/c9cbda2498a685517ad0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type Person struct { | |
Name string | |
Favorite string | |
} | |
func main() { | |
p := new(Person) | |
p.Name = "sekky" | |
p.Favorite = "Programming" | |
fmt.Printf("構造体 = %v", p) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
構造体 = &{sekky Programming} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
str := "Go" | |
fmt.Printf("文字列 = %s\n", str) | |
s := []string{"Go", "Java"} | |
fmt.Printf("スライス = %s", s) | |
// 配列では使用できないため、以下のコードはエラーになる | |
// s := [2]string{"Go", "Java"} | |
// fmt.Printf("配列 = %s", s) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
文字列 = Go | |
スライス = [Go Java] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
// %b 基数2 | |
b := 5 | |
fmt.Printf("基数2 = %b\n", b) | |
// %c 対応するUnicodeコードポイントによって表される文字 | |
c := '\101' | |
fmt.Printf("Unicodeコードポイント = %c\n", c) | |
// %d 基数10 | |
d := 5 | |
fmt.Printf("基数10 = %d\n", d) | |
// %o 基数8 | |
o := 20 | |
fmt.Printf("基数8 = %o\n", o) | |
// %x 基数16、10以上の数には小文字(a-f)を使用 | |
x := 2059 | |
fmt.Printf("基数16、10以上の数には小文字(a-f)を使用 = %x\n", x) | |
// %X 基数16、10以上の数には大文字(A-F)を使用 | |
X := 2059 | |
fmt.Printf("基数16、10以上の数には大文字(A-F)を使用 = %X\n", X) | |
// %U ユニコードフォーマット: U+1234; "U+%x"と同じ。デフォルトは、4桁 | |
U := '\101' | |
fmt.Printf("ユニコードフォーマット = %U\n", U) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
基数2 = 101 | |
Unicodeコードポイント = A | |
基数10 = 5 | |
基数8 = 24 | |
基数16、10以上の数には小文字(a-f)を使用 = 80b | |
基数16、10以上の数には大文字(A-F)を使用 = 80B | |
ユニコードフォーマット = U+0041 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type Person struct { | |
Name string | |
Favorite string | |
} | |
func main() { | |
p := new(Person) | |
p.Name = "sekky" | |
p.Favorite = "Programming" | |
fmt.Printf("構造体 = %p", p) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
構造体 = 0x1040a130 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type Person struct { | |
Name string | |
Favorite string | |
} | |
func main() { | |
p := new(Person) | |
p.Name = "sekky" | |
p.Favorite = "Programming" | |
fmt.Printf("構造体 = %+v", p) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
構造体 = &{Name:sekky Favorite:Programming} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type Person struct { | |
Name string | |
Favorite string | |
} | |
func main() { | |
p := new(Person) | |
p.Name = "sekky" | |
p.Favorite = "Programming" | |
fmt.Printf("構造体 = %#v\n", p) | |
a := [...]string{"Go", "Java", "Python", "Ruby", "Rust"} | |
fmt.Printf("配列 = %#v", a) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
構造体 = &main.Person{Name:"sekky", Favorite:"Programming"} | |
配列 = [5]string{"Go", "Java", "Python", "Ruby", "Rust"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type Person struct { | |
Name string | |
Favorite string | |
} | |
func main() { | |
p := new(Person) | |
p.Name = "sekky" | |
p.Favorite = "Programming" | |
fmt.Printf("構造体 = %T\n", p) | |
a := [...]string{"Go", "Java", "Python", "Ruby", "Rust"} | |
fmt.Printf("配列 = %T\n", a) | |
s := []int{0, 1, 2} | |
fmt.Printf("スライス = %T\n", s) | |
n := 7 | |
fmt.Printf("int = %T\n", n) | |
str := "sekky" | |
fmt.Printf("string = %T\n", str) | |
b := true | |
fmt.Printf("bool = %T\n", b) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
構造体 = *main.Person | |
配列 = [5]string | |
スライス = []int | |
int = int | |
string = string | |
bool = bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type Person struct { | |
Name string | |
Favorite string | |
} | |
func main() { | |
b := true | |
fmt.Printf("%t\n", b) | |
b = false | |
fmt.Printf("%t\n", b) | |
str := "Go" | |
fmt.Printf("%t\n", str) | |
n := 1 | |
fmt.Printf("%t\n", n) | |
p := new(Person) | |
p.Name = "sekky" | |
fmt.Printf("%t\n", p) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
true | |
false | |
%!t(string=Go) | |
%!t(int=1) | |
&{%!t(string=sekky) %!t(string=)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment