Go 自学:Array阵列

阅读 46

2023-09-02

以下代码展示了用两种方法建立array。

package main

import "fmt"

func main() {

	var fruitList [4]string

	fruitList[0] = "Apple"
	fruitList[1] = "Tomato"
	fruitList[3] = "Peach"

	fmt.Println("Fruit list is: ", fruitList)
	fmt.Println("The length of fruit list is: ", len(fruitList))

	var vegList = [5]string{"potato", "beans", "mushroom"}
	fmt.Println("Vegy list is: ", vegList)
	fmt.Println("The length of vegy list is: ", len(vegList))

}

输出为:
Fruit list is: [Apple Tomato Peach]
The length of fruit list is: 4
Vegy list is: [potato beans mushroom ]
The length of vegy list is: 5

精彩评论(0)

0 0 举报