Skip to content

posts/2021-06-01-go%E8%AF%AD%E8%A8%80%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/ #16

@utterances-bot

Description

@utterances-bot

Go语言基本数据结构 | 🏠 Less is more

摘要:Go语言基本数据结构
数组 # 1strings := [3]string{"1", "2", "2"} 2intArray := [8]int{1, 2, 3, 4, 5, 5, 5, 55} 定义两个数组,fmt.Println(len(strings)) 可以使用len()函数得到数组的长度,strings[1]可以获取指定数组下标的元素。
所以通过以下方式可以遍历数组:
1for i := 0; i < len(strings); i++ { 2 fmt.Println(strings[i]) 3} 下文提供了更加优雅的方式。
slice # Go数组的长度不可变,Go提供了一种内置类型切片:slice,与数组相比,切片的长度

https://archieyao.github.io/posts/2021-06-01-go%E8%AF%AD%E8%A8%80%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions