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

相关推荐
FfHUCisI5 分钟前
Go 编译过程全景
开发语言·后端·golang
FfHUCisI6 分钟前
Golang 语法分析与 AST:Parser 与 go/ast
开发语言·后端·golang
lemon_sjdk1 小时前
ObjectProperty
java·开发语言·算法
大模型码小白1 小时前
Spring AI Tool 实现自然语言操作 MySQL 数据库详解
服务器·开发语言·数据库·人工智能·python·mysql·spring
hh9501 小时前
Agent Plan x DeepSeek Harness:Agent 供应链安全与第三方插件审计
java·开发语言·安全·agent plan·adg成都社区·adg社区
「QT(C++)开发工程师」2 小时前
C++ std::move 详解
开发语言·c++
matlab代码2 小时前
基于matlab的玉米种子计数设计(GUI界面)【源码58期】
开发语言·matlab
c#上位机2 小时前
C#上位机项目实战——C#的dll项目编译时拷贝到指定目录下
开发语言·c#
Littlehero_1212 小时前
QT自定义控件之内嵌报表(4)(源码开源)
开发语言·qt