Go (golang) Tutorials - Slices Part II

Опубликовано: 27 Март 2018
на канале: Ambasoft Java
141
4

#golang #go #slices

Slices - Part II
-----------------
1.Append values to a slice
2.Append to a slice from a slice
3.Iterating slice - for.. range

slicedemo.go
-------------
package main
import "fmt"
func main(){
names:=[]string{"one","two","three","four"} //length and capacity is 4
names=append(names,"five")//length is 5, capacity got doubled and is now 8
fmt.Printf("The length of names is %d and capacity of names is %d\n",len(names),cap(names))
}


appendslicedemo.go
-------------------
package main
import "fmt"
func main(){
x:=[]int{10,20,30}
y:=[]int{40,50,60}
fmt.Println(append(x,y...)) //Values from both the slices were appended
//Use For loop
fmt.Println(x[i])

//For range loop - for each loop
for i, value := range y { //"value" is the variable which can hold or contain the 'i'th value from slice "y", where "i" is the index of iterative for loop
fmt.Printf("index is %d, value is %d\n",i,value)
}
}


Смотрите видео Go (golang) Tutorials - Slices Part II онлайн, длительностью часов минут секунд в хорошем качестве, которое загружено на канал Ambasoft Java 27 Март 2018. Делитесь ссылкой на видео в социальных сетях, чтобы ваши подписчики и друзья так же посмотрели это видео. Данный видеоклип посмотрели 141 раз и оно понравилось 4 посетителям.