Go Language Learning Note 2018-09-06

Source: Internet
Author: User

1 Add elements to slice, we use append to bring the function.

From the above steps we know s2=[5,6], continue to add data to slice more than the CAP, the system itself will open up a new underlying array for ease of use, but also remove the unused slice.






2 Examples:

Note that there is no null in the go language, he replaces the concept with nil , and that is, in the Go language, nil refers to 0, that is, its empty is 0, unless the condition is set, otherwise there is no way to execute the meaning oh.

For example, the first nil in this case

3 make (with function) usage: The makes function can display the contents of the array, the length (lens), and the Capacity (CAP).


The output of the S1,S2,S3 is:


4 Copy Slice


Copy (b), copy B to a as a template.

5 Delect Slice

Delete Intermediate data

Note Here s2[4:] ... In the "..." usage, when we want to take s2[4:] All the elements, need to add ... to fetch.

Remove the elements from the tail:

Note the use of the function Len when removing the trailing element.

The output is:


6 Operation of Map:
(1) Set the value:

Three ways of expression:


Note: Before a colon in map denotes key, the colon indicates value.

(2) Traverse map:


As before, we use range.

(3) Value:

The output is:


Make the following explanations:

The first OK we can take the value of this key called course is Golang;

So show as Ture

The second OK is assigned to couse at the time of assignment, and the key is not couse in our defined map, so this OK value is false.

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.