modified: eBook/18.1.md

modified:   eBook/18.11.md
	modified:   eBook/18.2.md
	modified:   eBook/18.3.md
This commit is contained in:
songleo
2016-01-03 14:49:10 +08:00
parent b3550e98e3
commit 706c594a7e
4 changed files with 10 additions and 9 deletions

View File

@@ -15,7 +15,7 @@ s2:= string(c) // s2 == "cello"
substr := str[n:m] substr := str[n:m]
``` ```
3如何使用for或者for-range遍历一个字符串 3如何使用`for`或者`for-range`遍历一个字符串:
```go ```go
// gives only the bytes: // gives only the bytes:

View File

@@ -8,7 +8,7 @@
4尽可能的使用数组和切片代替映射详见 参考文献15 4尽可能的使用数组和切片代替映射详见 参考文献15
5如果只想获取切片中某项值不需要值的索引尽可能的使用`for range`去遍历切片,这比必须去查询切片中的每个元素要快一些; 5如果只想获取切片中某项值不需要值的索引尽可能的使用`for range`去遍历切片,这比必须去查询切片中的每个元素要快一些
6当数组元素是稀疏的例如有很多0值或者空值使用映射会降低内存消耗 6当数组元素是稀疏的例如有很多0值或者空值使用映射会降低内存消耗

View File

@@ -1,15 +1,16 @@
# 18.2 数组和切片 # 18.2 数组和切片
创建: `arr1 := new([len]type)` 创建:
`arr1 := new([len]type)`
`slice1 := make([]type, len)` `slice1 := make([]type, len)`
初始化:`arr1 := [...]type{i1, i2, i3, i4, i5}` 初始化:
`arr1 := [...]type{i1, i2, i3, i4, i5}`
`arrKeyValue := [len]type{i1: val1, i2: val2}` `arrKeyValue := [len]type{i1: val1, i2: val2}`
`var slice1 []type = arr1[start:end]`
`var slice1 []type = arr1[start:end]`
1如何截断数组或者切片的最后一个元素 1如何截断数组或者切片的最后一个元素

View File

@@ -16,7 +16,7 @@ for key, value := range map1 {
`val1, isPresent = map1[key1]` `val1, isPresent = map1[key1]`
返回值: `key1`对应的值或者`0`, `true`或者`false` 返回值`key1`对应的值或者`0`, `true`或者`false`
3如何在映射中删除一个键 3如何在映射中删除一个键