Created
October 18, 2021 08:04
-
-
Save FrankFang/1999f20a1f3d887f7cc512909df9f476 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
"math" | |
) | |
func main() { | |
var age int8 = 18 // -128 ~ 127 | |
var daysToLive int16 = 10_000 // -32768 ~ 32767 | |
var qq int32 = 123_456_789 // 正负21亿左右 | |
var newqq int64 = 123_456_789_012 // 正负9e18左右 | |
var n int = 1000 | |
var hi []rune = []rune{'\u4f60', '\u597d'} // 你好,两个字符 | |
var bin []byte = []byte{'a', 'b', 'c', 'd'} // 字节数组 | |
var words string = "大家好,我是字符串" | |
var score float32 = 11.2 | |
var pi float64 = math.Pi | |
fmt.Println(age, daysToLive, qq, newqq, n, score, pi) | |
// 18 10000 123456789 123456789012 1000 11.2 3.141592653589793 | |
fmt.Println(string(hi), hi) | |
// 你好 [20320 22909] | |
fmt.Printf("%c,%c \n", hi[0], hi[1]) // %c 表示字符 | |
// 你,好 | |
fmt.Printf("%#X \n", bin) // %#X 表示以十六进制的形式展示 | |
// 0X61626364 | |
fmt.Println(words) | |
// 大家好,我是字符串 | |
fmt.Printf("%c \n", words[0]) | |
// å | |
fmt.Printf("%c \n", []rune(words)[0]) | |
// 大 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment