Go 自学:Array阵列

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

go 复制代码
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

相关推荐
他们都不看好你,偏偏你最不争气22 分钟前
【iOS】AFNetworking
开发语言·macos·ios·objective-c
Bigemap29 分钟前
BigemapPro快速添加历史影像(Arcgis卫星地图历史地图)
java·开发语言
进击的_鹏41 分钟前
【C++11】initializer_list列表初始化、右值引用和移动语义、可变参数模版等
开发语言·c++
mark-puls1 小时前
C语言打印爱心
c语言·开发语言·算法
西阳未落1 小时前
C语言柔性数组详解与应用
c语言·开发语言·柔性数组
Huhbbjs1 小时前
SQL 核心概念与实践总结
开发语言·数据库·sql
咕噜咕噜啦啦1 小时前
Qt之快捷键、事件处理、自定义按键——完成记事本项目
开发语言·qt
Source.Liu1 小时前
【Pywinauto库】12.1 pywinauto.backend 后端内部实施模块
开发语言·windows·python·自动化
晚云与城1 小时前
今日分享:C++ deque与priority_queue
开发语言·c++
半梦半醒*1 小时前
正则表达式
linux·运维·开发语言·正则表达式·centos·运维开发