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

相关推荐
Dxy12393102161 小时前
Python PDFplumber详解:从入门到精通的PDF处理指南
开发语言·python·pdf
EutoCool2 小时前
Qt:布局管理器Layout
开发语言·c++·windows·嵌入式硬件·qt·前端框架
Cyanto3 小时前
Spring注解IoC与JUnit整合实战
java·开发语言·spring·mybatis
写不出来就跑路3 小时前
WebClient与HTTPInterface远程调用对比
java·开发语言·后端·spring·springboot
悠哉清闲3 小时前
C++ MediaCodec H264解码
开发语言·c++
张人玉3 小时前
c#中Random类、DateTime类、String类
开发语言·c#
Jinkxs4 小时前
JavaScript性能优化实战技术
开发语言·javascript·性能优化
ydm_ymz5 小时前
C语言初阶4-数组
c语言·开发语言
presenttttt5 小时前
用Python和OpenCV从零搭建一个完整的双目视觉系统(六 最终篇)
开发语言·python·opencv·计算机视觉
逐花归海.5 小时前
『 C++ 入门到放弃 』- 多态
开发语言·c++·笔记·程序人生