go slice Expand

You can use  ... operator to append to the other end of the slice sections:

Copy the code
package main

import (  
    "fmt"
)

func main() {  
    veggies := []string{"potatoes","tomatoes","brinjal"}
    fruits := []string{"oranges","apples"}
    food := append(veggies, fruits...)
    fmt.Println("food:",food)
}
Copy the code

The above procedure , in the first 10 rows  fruits appended to  veggies and assigned to  food. ...Operator is used to expand the slice. The output of the program food: [potatoes tomatoes brinjal oranges apples]is: .

Guess you like

Origin www.cnblogs.com/ExMan/p/11468824.html