Files
go_test/5.数组索引.go

25 lines
628 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)
}