0
点赞
收藏
分享

微信扫一扫

Go 自学:Array阵列

王老师说 2023-09-02 阅读 46

以下代码展示了用两种方法建立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 条评论