当前位置:网站首页>Go language learning notes - array | go language from scratch
Go language learning notes - array | go language from scratch
2022-04-23 09:18:00 【Swordsman a Liang_ ALiang】
Learning notes , Where is where .
Comparing to conventional , and Java similar .
The sample code is as follows
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{" Xiao Wang ", " petty thief ", " Xiao Zhang "}
girls := []string{" Xiaomei ", " Small circle ", " floret "}
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()
}
Execution results
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=[ Xiao Wang petty thief Xiao Zhang ]
row=0,id=0,name= Xiao Wang
row=0,id=1,name= petty thief
row=0,id=2,name= Xiao Zhang
row=1,stu=[ Xiaomei Small circle floret ]
row=1,id=0,name= Xiaomei
row=1,id=1,name= Small circle
row=1,id=2,name= floret
Be careful
1、 If the array length is uncertain , have access to "..." Instead of array length , A special , The compiler will infer {} Inner length .
2、 You can use the built-in len()、cap() Method to get the length of the array , And the maximum capacity .
3、 Multidimensional arrays can use append() Method to add a one-dimensional array to a multi-dimensional array .
Summary
Looking back at the slices , Review the array .
版权声明
本文为[Swordsman a Liang_ ALiang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230633437900.html
边栏推荐
- 三、6【Verilog HDL】基础知识之门级建模
- Kettle实验
- Kettle实验 转换案例
- What is monitoring intelligent playback and how to use intelligent playback to query video recording
- Rembg split mask
- Matlab draw five-star red flag
- Number of islands
- 《数字电子技术基础》3.1 门电路概述、3.2 半导体二极管门电路
- Kettle experiment (III)
- Flink SQL realizes the integration of stream and batch
猜你喜欢

node安装

Introduction to matlab

112. 路径总和

Kettle experiment

valgrind和kcachegrind使用運行分析

108. Convert an ordered array into a binary search tree

Data visualization: use Excel to make radar chart
![[58] length of the last word [leetcode]](/img/c5/3ba1fe5a81593d9576bb597f0d5f45.png)
[58] length of the last word [leetcode]

Cross domain configuration error: when allowcredentials is true, allowedorigins cannot contain the special value "*“

Failed to download esp32 program, prompting timeout
随机推荐
Data visualization: use Excel to make radar chart
GoLand debug go use - white record
Four pictures to understand some basic usage of Matplotlib
kettle实验
108. Convert an ordered array into a binary search tree
npm ERR! network
Kettle experiment
[58] length of the last word [leetcode]
Leetcode-199 - right view of binary tree
Notes on xctf questions
RSA 加密解密签名验签
valgrind和kcachegrind使用运行分析
RSA encryption and decryption signature verification
What is augmented reality technology? Where can it be used?
node安装
Get trustedinstaller permission
2021 Li Hongyi's adaptive learning rate of machine learning
How to read excel table to database
Go language self-study series | golang method
政务中台研究目的建设目标,建设意义,技术创新点,技术效果