Go basic data structure exercises: arrays, slices, maps

Source: Internet
Author: User

Follow the "GO in ACTION" book.

It should be the second time Oh ~ ~

Package Mainimport ("FMT") func main () {array: = [5]*int{0:new (int), 3:new (int)}*array[3] = 50/*for k, V: = range Array { Fmt. Println (*array[k], K, v)}*/fmt. Println (*array[3]) var array1 [3]*stringarray2: = [3]*string{new (String), new (string), new (string)}*array2[0] = "Red" * ARRAY2[1] = "Blue" *array2[2] = "Green" array1 = array2*array1[1] = "Black" FMT. Println (array1) fmt. Println (array2) for k, V: = Range Array1 {fmt. Println (*array1[k], K, *v)}for k, V: = Range Array2 {fmt. Println (*array2[k], K, *v)}slice: = []int{10, +, +, 50}newslice: = slice[1:3:3]newslice[1] = 35newSlice = Append (new Slice, Newslice = append (newslice) Newslice = append (Newslice,) Newslice = append (Newslice, all) Slice = Append (slic E, slice = append (slice, d) slice = append (slice, d) newslice = Append (Newslice, +) Slice1: = []int{10, +,-40}new Slice1: = Append (Slice1, a) slice1[2] = 200newslice1[2] = 2000fmt. Println (Slice) fmt. Println (Newslice) fmt. Println (Slice1) fmt. Println (NewSlice1) for index, Value: =Range Slice {fmt. Printf ("Index:%d value:%d\n", index, value)}for index: = 2; Index < Len (slice); index++ {fmt. Printf ("Index:%d Value:%d\n", index, Slice[index])}source: = []string{"Apple", "Orange", "Plum", "Banana", "Grape"}news Ource: = source[2:3:4]fmt. Println (source) fmt. Println (newsource) S1: = []int{1, 2}s2: = []int{3, 4}fmt. Printf ("%v\n", append (S1, S2 ...)) Colors: = map[string]string{"AliceBlue": "#f0f8ff", "Coral": "#ff7F50", "Darkgray": "#a9a9a9", "Forestgreen": "#22 8b22 ",}delete (Colors," Coral ") for key, value: = Range colors {fmt. Printf ("Key:%s value:%s\n", Key, Value)}}

  

Go basic data structure exercises: arrays, slices, maps

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.