Go Append method

Source: Internet
Author: User

Append is used to add elements to the end of a slice and return results.
Look at the code:

" FMT " Func Main () {x:= []int {1,2,3}y:= []int {4 ,5,6}// Note the following two differences between FMT. Println (Append (x,4,5,6)) fmt. Println (Append (x, y ...));}

Output Result:

[1 2 3 4 5 6]
[1 2 3 4 5 6]

There are two ways to use append:
Slice = append (slice, elem1, elem2)
Slice = append (slice, anotherslice ...)

In the first usage, the first argument is slice, and you can add multiple parameters later.
If you are stitching together two slice, you will need to use the second one, add three points after the name of the second slice, and this time append only supports two parameters and does not support any number of arguments.

Go Append method

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.