数组索引基本懂了,头痛,感觉切片好难,下次再学一下,我先睡一下了

This commit is contained in:
2025-11-22 10:52:55 +08:00
parent 2a76fecb32
commit 6bd20511f7
3 changed files with 83 additions and 0 deletions

25
5.数组索引.go Normal file
View File

@@ -0,0 +1,25 @@
package main
import "fmt"
func main() {
list_()
}
func list_() {
// 数组
var nameList [3]string = [3]string{"skimrme", "lukychen", "Qmeimei"}
fmt.Println(nameList)
// 索引
// "skimrme" "lukychen" "Qmeimei"
// 0 1 2 正向索引
// -3 -2 -1 负向索引
fmt.Println(nameList[0]) // 正向索引取值
fmt.Println(nameList[2])
fmt.Println(nameList[len(nameList)-2]) // 负向索引取值 go语言原则上不支持的骚操作
// 数组可被切换 但是仿佛是自上而下的
nameList[len(nameList)-2] = "123"
fmt.Println(nameList)
}