当前位置:网站首页>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
边栏推荐
- Leetcode-199 - right view of binary tree
- Download and install bashdb
- MySQL small exercise (only suitable for beginners, non beginners are not allowed to enter)
- Write down the post order traversal of the ~ binary tree
- nn. Explanation of module class
- Installation of data cleaning ETL tool kettle
- Pctp test experience sharing
- Image processing in opencv -- Introduction to contour + contour features
- Applet error: should have URL attribute when using navigateto, redirectto or switchtab
- [indexof] [lastIndexOf] [split] [substring] usage details
猜你喜欢
《信息系统项目管理师总结》第八章 项目干系人管理
Cross domain configuration error: when allowcredentials is true, allowedorigins cannot contain the special value "*“
Project upload part
npm ERR! network
Resource packaging dependency tree
Production practice elk
Applet error: should have URL attribute when using navigateto, redirectto or switchtab
Distributed message oriented middleware framework selection - Digital Architecture Design (7)
Experimental report on analysis of overflow vulnerability of assembly language and reverse engineering stack
ATSS(CVPR2020)
随机推荐
Go language self-study series | golang method
Applet in wechat and app get current ()
Kettle experiment (III)
Introduction to matlab
【SQL server速成之路】数据库的视图和游标
LeetCode_ DFS_ Medium_ 1254. Count the number of closed islands
Go language self-study series | golang structure as function parameter
Employee probation application (Luzhou Laojiao)
[SQL Server fast track] view and cursor of database
資源打包關系依賴樹
Kettle实验 (三)
Go language self-study series | initialization of golang structure
Is Zhongyan futures safe and reliable?
Rembg split mask
Talent Plan 学习营初体验:交流+坚持 开源协作课程学习的不二路径
How to protect open source projects from supply chain attacks - Security Design (1)
Research purpose, construction goal, construction significance, technological innovation, technological effect
[original] use system Text. JSON formats the JSON string
LGB, XGB, cat, k-fold cross validation
Wechat applet catchtap = "todetail" event problem