- 金錢
- 119
- 威望
- 1045
- 貢獻值
- 30
- 推廣值
- 0
- 性別
- 保密
- 在線時間
- 122 小時
- 最後登錄
- 2024-11-21
- 主題
- 68
- 精華
- 0
- 閱讀權限
- 50
- 註冊時間
- 2011-1-15
- 帖子
- 276
TA的每日心情 | 衰 7 天前 |
---|
簽到天數: 1144 天 [LV.10]以壇為家III - 推廣值
- 0
- 貢獻值
- 30
- 金錢
- 119
- 威望
- 1045
- 主題
- 68
|
[size=0.92857em]25个关键字
[size=0.92857em][size=0.92857em]break [size=0.92857em]default [size=0.92857em]func [size=0.92857em]interface [size=0.92857em]select
[size=0.92857em][size=0.92857em]case [size=0.92857em]defer [size=0.92857em]go [size=0.92857em]map [size=0.92857em]struct
[size=0.92857em][size=0.92857em]chan [size=0.92857em]else [size=0.92857em]goto [size=0.92857em]package [size=0.92857em]switch
[size=0.92857em][size=0.92857em]const [size=0.92857em]fallthrough [size=0.92857em]if [size=0.92857em]range [size=0.92857em]type
[size=0.92857em][size=0.92857em]continue [size=0.92857em]for [size=0.92857em]import [size=0.92857em]return [size=0.92857em]var
[size=0.92857em][size=0.92857em]
[size=0.92857em][size=0.92857em]37个保留字
[size=0.92857em][size=0.92857em]Constants[size=0.92857em]: [size=0.92857em]true [size=0.92857em]false [size=0.92857em]iota [size=0.92857em]nil
[size=0.92857em][size=0.92857em]Types[size=0.92857em]: [size=0.92857em]int [size=0.92857em]int8 [size=0.92857em]int16 [size=0.92857em]int32 [size=0.92857em]int64
[size=0.92857em][size=0.92857em]uint [size=0.92857em]uint8 [size=0.92857em]uint16 [size=0.92857em]uint32 [size=0.92857em]uint64 [size=0.92857em]uintptr
[size=0.92857em][size=0.92857em]float32 [size=0.92857em]float64 [size=0.92857em]complex128 [size=0.92857em]complex64
[size=0.92857em][size=0.92857em]bool [size=0.92857em]byte [size=0.92857em]rune [size=0.92857em]string [size=0.92857em]error
[size=0.92857em][size=0.92857em]Functions[size=0.92857em]: [size=0.92857em]make [size=0.92857em]len [size=0.92857em]cap [size=0.92857em]new [size=0.92857em]append [size=0.92857em]copy [size=0.92857em]close [size=0.92857em]delete
[size=0.92857em][size=0.92857em]complex [size=0.92857em]real [size=0.92857em]imag
[size=0.92857em][size=0.92857em]panic recover
[size=0.92857em]函数体外必须使用关键字开头
[size=0.92857em]标准声明
[size=0.92857em]var 变量名 变量类型
[size=0.92857em]var name string
[size=0.92857em]批量声明
[size=0.92857em]var (
[size=0.92857em] name string
[size=0.92857em])
[size=0.92857em]声明并赋值
[size=0.92857em]var name string = "niekx"
[size=0.92857em]类型推导
[size=0.92857em]var name = "niex"
[size=0.92857em]短变量声明(只能用在函数体中)
[size=0.92857em]m := 10
[size=0.92857em]匿名变量,短下划线去接收
[size=0.92857em][size=0.92857em]func [size=0.92857em]foo[size=0.92857em]([size=0.92857em]) [size=0.92857em]([size=0.92857em]int[size=0.92857em], [size=0.92857em]string[size=0.92857em]) [size=0.92857em]{
[size=0.92857em][size=0.92857em]return [size=0.92857em]10[size=0.92857em], [size=0.92857em]"Q1mi"[size=0.92857em]}
[size=0.92857em][size=0.92857em]func [size=0.92857em]main[size=0.92857em]([size=0.92857em]) [size=0.92857em]{
[size=0.92857em][size=0.92857em]x[size=0.92857em], [size=0.92857em]_ [size=0.92857em]:= [size=0.92857em]foo[size=0.92857em]([size=0.92857em])
[size=0.92857em][size=0.92857em]_[size=0.92857em], [size=0.92857em]y [size=0.92857em]:= [size=0.92857em]foo[size=0.92857em]([size=0.92857em])
[size=0.92857em][size=0.92857em]fmt[size=0.92857em].[size=0.92857em]Println[size=0.92857em]([size=0.92857em]"x="[size=0.92857em], [size=0.92857em]x[size=0.92857em])
[size=0.92857em][size=0.92857em]fmt.Println("y=", y)
[size=0.92857em][size=0.92857em]}
[size=0.92857em]常量:const,常量定义的时候必须赋值
[size=0.92857em]iota [size=0.92857em]iota是go语言的常量计数器,只能在常量的表达式中使用。
[size=0.92857em][size=0.92857em]iota在const关键字出现时将被重置为0。const中每新增一行常量声明将使[size=0.92857em]iota计数一次(iota可理解为const语句块中的行索引)。 使用iota能简化定义,在定义枚举时很有用。
[size=0.92857em]
[size=0.92857em][size=0.92857em]const [size=0.92857em](
[size=0.92857em][size=0.92857em]n1 [size=0.92857em]= [size=0.92857em]iota [size=0.92857em]//0
[size=0.92857em][size=0.92857em]n2 [size=0.92857em]//1
[size=0.92857em][size=0.92857em]n3 [size=0.92857em]//2
[size=0.92857em][size=0.92857em]n4 [size=0.92857em]//3
[size=0.92857em][size=0.92857em])
|
|