当前位置:网站首页>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
边栏推荐
猜你喜欢
Multi view depth estimation by fusing single view depth probability with multi view geometry
BK3633 规格书
2021 Li Hongyi's adaptive learning rate of machine learning
Brush classic topics
I don't understand time, timestamp and time zone. Look at this article
653. Sum of two IV - input BST
What is monitoring intelligent playback and how to use intelligent playback to query video recording
Machine learning (VI) -- Bayesian classifier
Mini - exercice MySQL (seulement pour les débutants, pas pour les non - débutants)
Brief steps to build a website / application using flash and H5
随机推荐
【原创】使用System.Text.Json对Json字符串进行格式化
Distributed message oriented middleware framework selection - Digital Architecture Design (7)
[C language] document operation
Go language self-study series | golang nested structure
Share the office and improve the settled experience
To remember the composition ~ the pre order traversal of binary tree
SQL used query statements
Group Backpack
NPM installation yarn
爬虫使用xpath解析时返回为空,获取不到相应的元素的原因和解决办法
Taxable income
Wechat applet catchtap = "todetail" event problem
Bk3633 specification
ASUS laptop can't read USB and surf the Internet after reinstalling the system
Kettle experiment
Is Zhongyan futures safe and reliable?
Kettle实验 (三)
Kettle实验
Correct method of calculating inference time of neural network
政务中台研究目的建设目标,建设意义,技术创新点,技术效果