当前位置:网站首页>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
边栏推荐
- NPM reports an error: operation not allowed, MKDIR 'C: \ program files \ node JS \ node_ cache _ cacache’
- kettle实验
- Failed to download esp32 program, prompting timeout
- Base de la technologie électronique numérique 3.1 aperçu du circuit de porte, 3.2 circuit de porte à diode semi - conductrice
- How to read excel table to database
- 108. Convert an ordered array into a binary search tree
- Error: cannot find or load main class
- Talent Plan 学习营初体验:交流+坚持 开源协作课程学习的不二路径
- Node installation
- Employee probation application (Luzhou Laojiao)
猜你喜欢

小程序报错:Cannot read property 'currentTarget' of undefined

Strength comparison vulnerability of PHP based on hash algorithm

First principle mind map

三、6【Verilog HDL】基础知识之门级建模

Flink SQL realizes the integration of stream and batch

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

数据清洗 ETL 工具Kettle的安装

SAP 101K 411k inventory change

Introduction to matlab

npm报错 :operation not permitted, mkdir ‘C: \Program Files \node js \node_ cache _ cacache’
随机推荐
Leetcode-199 - right view of binary tree
653. Sum of two IV - input BST
Valgrind et kcachegrind utilisent l'analyse d'exécution
Trc20 fund collection solution based on thinkphp5 version
Wechat applet catchtap = "todetail" event problem
[indexof] [lastIndexOf] [split] [substring] usage details
Harbor enterprise image management system
《數字電子技術基礎》3.1 門電路概述、3.2 半導體二極管門電路
A must see wechat applet development guide 1 - basic knowledge
What is monitoring intelligent playback and how to use intelligent playback to query video recording
三、6【Verilog HDL】基础知识之门级建模
tsdf +mvs
Arbre de dépendance de l'emballage des ressources
What is augmented reality technology? Where can it be used?
Single sign on SSO
Kettle experiment conversion case
【读书笔记】《Verilog数字系统设计教程》 第5章 条件语句、循环语句和块语句(附思考题答案)
To remember the composition ~ the pre order traversal of binary tree
Group Backpack
Number theory to find the sum of factors of a ^ B (A and B are 1e12 levels)