In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to set slice interception in Go language". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to set slice interception in Go language".
Slice truncation
You can set the lower and upper limits to intercept slices [lower-bound:upper-bound]. Examples are as follows:
Example
Package main
Import "fmt"
Func main () {
/ * create a slice * /
Numbers: = [] int {0pm 1pm 2je 3je 4J 5pm 6je 7je 8}
PrintSlice (numbers)
/ * print the original slice * /
Fmt.Println ("numbers = =", numbers)
/ * print subslices from index 1 (inclusive) to index 4 (not included) * /
Fmt.Println ("numbers [1:4] =", numbers [1:4])
/ * the default lower limit is 0 percent /
Fmt.Println ("numbers [: 3] =", numbers [: 3])
/ * the default upper limit is len (s) * /
Fmt.Println ("numbers [4:] =", numbers [4:])
Numbers1: = make ([] int,0,5)
PrintSlice (numbers1)
/ * print subslices from index 0 (inclusive) to index 2 (not included) * /
Number2: = numbers [: 2]
PrintSlice (number2)
/ * print subslices from index 2 (inclusive) to index 5 (not included) * /
Number3: = numbers [2:5]
PrintSlice (number3)
}
Func printSlice (x [] int) {
Fmt.Printf ("len=%d cap=%d slice=%v\ n", len (x), cap (x), x)
}
The output result of executing the above code is:
Len=9 cap=9 slice= [0 1 2 3 4 5 6 7 8] numbers = = [0 1 2 3 4 5 6 7 8] numbers [1:4] = [1 23] numbers [: 3] = [0 12] numbers [4:] = [4 56 7 8] len=0 cap=5 slice= [] len=2 cap=9 slice= [0 1] len=3 cap=7 slice= [2 34] Thank you for reading. This is the content of "how to set slice capture in Go language". After the study of this article, I believe that you have a deeper understanding of the problem of how to set slice interception in Go language, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.