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

相关推荐
yuzhiboyouye1 小时前
《阿里巴巴 Java 开发手册》的 MySQL 核心规范
java·开发语言·mysql
郝学胜-神的一滴1 小时前
Effective STL 条款12:对容器线程安全性的现实期望
c语言·开发语言·c++·qt·网络协议·rpc·numpy
geovindu2 小时前
python: KNeighborsClassifier K
开发语言·后端·python·算法
时间的情敌3 小时前
Three.js 射线拾取进阶:hover 高亮、点击弹窗、多物体过滤、穿透拾取
开发语言·javascript·three.js
Amumu121384 小时前
TypeScript学习: 基本类型(一)
开发语言·前端·typescript
敲上瘾5 小时前
Qt 常用控件:按钮、显示输入、容器与布局等
开发语言·c++·qt·qt6.3
船神丿男人5 小时前
C++ STL 入门:用 std::string 读配置,四个容易漏掉的边界
开发语言·c++
30955666617 小时前
股票接口重试怎么分类:正常、空数组与错误响应的幂等处理
java·大数据·开发语言·数据库·php·api接口·股票数据api接口
郝学胜-神的一滴18 小时前
Effective STL 条款09:慎重选择删除元素的方法
开发语言·网络·数据结构·c++·算法·stl