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

相关推荐
apocelipes1 天前
常用编程语言和库的正则表达式性能对比
c语言·c++·python·性能优化·golang·开发工具和环境
LDR00617 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术17 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript
码云数智-园园17 天前
C++20 Modules 模块详解
java·开发语言·spring
swordbob17 天前
NIO的channel中什么是 fd(File Descriptor,文件描述符)
java·开发语言·nio
源分享17 天前
Java线程同步的多种实现方法(非常详细)
java·开发语言·jvm
Luminous.17 天前
C语言--day30
c语言·开发语言
何以解忧,唯有..17 天前
Go语言循环语句详解:for、range与循环控制
开发语言·算法·golang
謓泽17 天前
C语言不是语法,是通往机器的地图。
c语言·开发语言
云水一下17 天前
从零开始学 PHP 系列(一):PHP 的前世今生与开发环境搭建
开发语言·php