Advanced path to the Go language-golang high-level data structure definition
Yun Zhengjie
Copyright Notice: Original works, declined reprint! Otherwise, the legal liability will be investigated.
We've previously learned about Golang's basic data types, strings and Byte, and Rune, but it's possible that we're still not quite sure about the high-level data types, so learn these advanced data type data with my footsteps today. I believe that some people may have learned python, so I do not have to read this blog basically, because you will feel so easy. Because there are so many similarities, it's just a different notation. This chapter focuses on arrays, slices (scice), dictionaries (maps), structures (structs), and so on.
One. Arrays
1. Define an empty array
1 Package Main2 3 Import "FMT"4 5 Func Main () {6var num [3]int//indicates that an array with a capacity of 3 is defined, and if no initial value is assigned, the default is"0".7Fmt. Printf ("The first number of the array is:%d\n", num[0])8Fmt. Printf ("The last number of the array is:%d\n", Num[len (num)-1])9 forI,v: =Range num {TenFmt. Printf ("The subscript for the array is:%d, the initial value corresponding to the array's subscript is:%d\n", I,v) One } A for_,v: =Range num { -Fmt. Printf ("the initial value of the array is:%d\n", V) - } the } - - - + #The result of the above code execution is as follows: - The first number of the array is: 0 + The last number of the array is: 0 A The subscript of the array is: 0, the initial value corresponding to the array subscript is: 0 atThe subscript for the array is: 1, the initial value corresponding to the array's subscript is: 0 -The subscript for the array is: 2, the initial value corresponding to the array's subscript is: 0 - the initial value of the array is: 0 - the initial value of the array is: 0 -The initial value of the array is: 0
2.
Advanced path to the Go language-golang high-level data structure definition