当前位置:网站首页>Go语学习笔记 - 数组 | 从零开始Go语言
Go语学习笔记 - 数组 | 从零开始Go语言
2022-04-23 06:34:00 【剑客阿良_ALiang】
学习笔记,写到哪是哪。
比较常规,和Java基本类似。
样例代码如下
package main
import "fmt"
func array1() {
var a = [5]int{1, 2, 3}
for i, c := range a {
fmt.Printf("%d - %d\n", i, c)
}
fmt.Printf("%v\n", a)
var b = [...]float64{1.0, 2.3, 1.9}
fmt.Printf("%v - %.2f length=%d\n", b, b[0], len(b))
students := [][]string{}
boys := []string{"小王", "小李", "小张"}
girls := []string{"小美", "小圆", "小花"}
students = append(students, boys)
students = append(students, girls)
for i, student := range students {
fmt.Printf("row=%d,stu=%v\n", i, student)
for j, d := range student {
fmt.Printf("row=%d,id=%d,name=%v\n", i, j, d)
}
}
}
func main() {
array1()
}
执行结果
0 - 1
1 - 2
2 - 3
3 - 0
4 - 0
[1 2 3 0 0]
[1 2.3 1.9] - 1.00 length=3
row=0,stu=[小王 小李 小张]
row=0,id=0,name=小王
row=0,id=1,name=小李
row=0,id=2,name=小张
row=1,stu=[小美 小圆 小花]
row=1,id=0,name=小美
row=1,id=1,name=小圆
row=1,id=2,name=小花
注意
1、数组长度如果不确定,可以使用"..."来代替数组长度,比较特殊,编译器会自行推断{}内的长度。
2、 可以使用内置的len()、cap()方法获取数组的长度,以及最大容纳数。
3、多维数组可以使用append()方法将一维数组加入到多维数组中。
小结
回头看切片的时候,回顾一下数组。
版权声明
本文为[剑客阿良_ALiang]所创,转载请带上原文链接,感谢
https://huyi-aliang.blog.csdn.net/article/details/124269105
边栏推荐
- SAP自建表log功能开启
- Internal network security attack and defense: a practical guide to penetration testing (IV): Authority improvement analysis and defense
- CTF-MISC学习之从开始到放弃
- Feign源码分析
- Internal network security attack and defense: a practical guide to penetration testing (5): analysis and defense of horizontal movement in the domain
- Introduction to sap query enhanced development
- Intranet penetration series: icmpsh of Intranet tunnel
- 内网渗透系列:内网隧道之icmp_tran
- 关于unity获取真实地理地图转3D化的相关链接
- sentinel集成nacos动态更新数据原理
猜你喜欢

How to present your digital portfolio: suggestions from creative recruiters

nacos源码分析思路

Towords Open World Object Detection

VBA appelle SAP RFC pour réaliser la lecture et l'écriture des données

Chapter V investment real estate

When using flash, the code ends automatically without an error, the connection cannot be maintained, and the URL cannot be accessed.

Houdini > variable building roads, learning process notes

内网渗透系列:内网隧道之pingtunnel

VBA調用SAP RFC實現數據讀取&寫入

BUUCTF MISC刷题
随机推荐
Unity gets the resources that a file depends on
《内网安全攻防:渗透测试实战指南》读书笔记(七):跨域攻击分析及防御
upload-labs 靶场练习
利用sqlmap注入获取网址管理员账号密码
Online Safe Trajectory Generation For Quadrotors Using Fast Marching Method and Bernstein Basis Poly
爬虫学习笔记,学习爬虫,看本篇就够了
Chapter IV intangible assets
DVWA靶场练习
Chapter V investment real estate
内网渗透系列:内网隧道之icmp_tran
How to present your digital portfolio: suggestions from creative recruiters
VBA调用SAP RFC实现数据读取&写入
内网渗透系列:内网隧道之pingtunnel
Internal network security attack and defense: a practical guide to penetration testing (8): Authority maintenance analysis and defense
数据库之MySQL——基本常用查询命令
一些靶场的学习记录:sqli-labs、upload-labs、XSS
How does Apache Hudi accelerate traditional batch mode?
VBA appelle SAP RFC pour réaliser la lecture et l'écriture des données
RAID0和RAID5的创建和模拟RAID5工作原理
Teach-Repeat-Replan: A Complete and Robust System for Aggressive Flight in Complex Environments