JUST筆記
Go語言主要特性
- 自動垃圾回收(Python: so easy?)
- 豐富內(nèi)置類型(Python: I don't think so)
- 函數(shù)多返回值(Python: I can)
- 錯誤處理(Python:are you sure?)
- 匿名函數(shù)和閉包(Python: give me something new?)
- 類型和接口(Python: Not bad!)
- 并發(fā)編程(Python: Yes, double click & 666)
- 反射(I do not use and I do not know)
- 語言交互性(Python: Now, I just found I like you)
Let's say "Hello World!"
package main
// you konw "one line comment"
import "fmt"
/* More
Line
Comment
*/
func main(){
fmt.Printf("Hello World!")
}
How to download
- Just google or baidu, I dont care. You all need just kown what's gopath
- I'm using vscode, perfect for me to code
聲明個變量
- var v int = 666
- v := 666
- var v = 666
- var v1 [3]int {6,6,6}
- var v2 []int {6,6,6}
- 匿名變量 _
- i, j = j, i
類型
- bool
- int8/byte/int16/int/uint
- float32/float64
- complex64/complex128(How to use?)
- string
- rune
- error
- 指針(pointer)
- 數(shù)組(array)
- 切片(slice)
- 字典(map)
- 通道(chan)
- 結(jié)構(gòu)體(struct)
- 接口(interface)
遍歷元素
package main
import "fmt"
func main(){
a = [3]int{6,6,6}
for i :=0; i<len(a); i++ {
fmt.Println(a[i])
}
for _, i := range a {
fmt.Println(i)
}
}
make
package main
import "fmt"
func main() {
//cap = 10 5個元素默認(rèn)為0 {0,0,0,0,0}
myslice := make([]int, 5, 10)
}
while? break?for?
package main
import "fmt"
func main() {
i := 0
for {
fmt.Println(i)
i ++
if i > 100 {
break
}
}
}
函數(shù)調(diào)用
- 小寫字母函數(shù)只在本包內(nèi)可見, 大寫字母開頭的函數(shù)才能被其他包調(diào)用
任意類型不定參數(shù)
func myfunc(args ...interface{}){
}
匿名函數(shù)(hah)
func (x, y int) bool{
return x < y
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。