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

相关推荐
Wang's Blog3 小时前
Go-Zero 项目开发43:基于 Filebeat 收集各个服务的日志信息
开发语言·golang·go-zero·filebeat
丈剑走天涯4 小时前
JDK 17 正式特性
java·开发语言
秋田君5 小时前
QT_QFontDialog类字体对话框
开发语言·qt
圣光SG5 小时前
Java操作题练习(七)
java·开发语言·算法
麻瓜老宋6 小时前
AI开发C语言应用按步走,表达式计算器calc的第二十三步,多行输入、进制输出、错误恢复、常量折叠、配置加载等
c语言·开发语言·atomcode
q567315236 小时前
企业级 HTTP 代理采购选型:技术评估清单 15 项
开发语言·网络·爬虫·网络协议·http·隧道ip·代理ip
天天进步20157 小时前
Python全栈项目--智能办公自动化系统
开发语言·python
cm04Z9c917 小时前
C#摸鱼实录——IoC与DI案例详解
开发语言·c#
long3168 小时前
Java 新手入门与实战开发指南
java·开发语言
摩西蒙8 小时前
计算机网络
开发语言·计算机网络·php