Section10-82
This commit is contained in:
22
Section10/81.go
Normal file
22
Section10/81.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
numbers := []int{2, 3}
|
||||||
|
|
||||||
|
numbers = append(numbers, 10)
|
||||||
|
fmt.Println(numbers)
|
||||||
|
|
||||||
|
numbers = append(numbers, 20, 30, 40)
|
||||||
|
fmt.Println(numbers)
|
||||||
|
|
||||||
|
n := []int{100, 200}
|
||||||
|
numbers = append(numbers, n...)
|
||||||
|
fmt.Println(numbers)
|
||||||
|
|
||||||
|
src := []int{10, 20, 30}
|
||||||
|
dst := make([]int, len(src))
|
||||||
|
nn := copy(dst, src)
|
||||||
|
fmt.Println(src, dst, nn)
|
||||||
|
}
|
||||||
22
Section10/82.go
Normal file
22
Section10/82.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
a := [5]int{1, 2, 3, 4, 5}
|
||||||
|
b := a[1:3]
|
||||||
|
fmt.Printf("%v, %T\n", b, b)
|
||||||
|
|
||||||
|
s1 := []int{1, 2, 3, 4, 5, 6}
|
||||||
|
s2 := s1[1:3]
|
||||||
|
fmt.Println(s2)
|
||||||
|
fmt.Println(s1[2:])
|
||||||
|
fmt.Println(s1[:3])
|
||||||
|
fmt.Println(s1[:])
|
||||||
|
|
||||||
|
s1 = append(s1[:4], 100)
|
||||||
|
fmt.Println(s1)
|
||||||
|
|
||||||
|
s1 = append(s1[:4], 200)
|
||||||
|
fmt.Println(s1)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user