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

相关推荐
aramae4 小时前
模拟实现strcmp()(C语言)
c语言·开发语言·后端
泡海椒5 小时前
PDF 表格样式优化:jquick-pdf 边框、圆角、背景色
java·开发语言·pdf
Beyond_System|系统之外5 小时前
【学编程】Python基础编程题100道(21-60)
开发语言·python·算法
景熙55236 小时前
15.Java 8 Stream 流入门到实战
java·开发语言·数据结构
Bruce_Liuxiaowei8 小时前
Python 实例赋值遮蔽类属性:一个从不报错的静默陷阱
开发语言·python·语法糖
aramae10 小时前
MySQL内置函数(7)
开发语言·笔记·后端·mysql·其他
五彩小白11 小时前
GO语言装饰器语法
golang
码行山野赴时序归途13 小时前
链表家族收官篇:循环链表
c语言·开发语言·数据结构·链表
景熙552313 小时前
单体项目编写思路和落地形式
java·开发语言
计算机毕设定制辅导-无忧学长14 小时前
《基于SpringBoot的未成年人健康知识科普平台的设计与实现》
java·开发语言·vue.js·spring boot·未成年人健康知识科普平台