首页 > 代码库 > GO的数组及切片

GO的数组及切片

感觉在向PYTHON学一些数组方面的功能。

package mainimport "fmt"func main() {    var myArray [10]int = [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}    var mySlice []int = myArray[:5]    fmt.Println("Elements of myArray: ")    for _, v := range myArray {        fmt.Print(v, " ")    }    fmt.Println("\nElements of mySlice: ")    for _, v := range mySlice {        fmt.Print(v, " ")    }    fmt.Println()}

package main

import "fmt"
func main() {
    var myArray [10]int = [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    var mySlice []int = myArray[:5]
    fmt.Println("Elements of myArray: ")
    for _, v := range myArray {
        fmt.Print(v, " ")
    }
    fmt.Println("\nElements of mySlice: ")
    for _, v := range mySlice {
        fmt.Print(v, " ")
    }
    fmt.Println()
}