File tree Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Original file line number Diff line number Diff line change @@ -386,7 +386,7 @@ slice有一些简便的操作
386
386
我们看下面的代码,` map ` 的读取和设置也类似` slice ` 一样,通过` key ` 来操作,只是` slice ` 的` index ` 只能是`int`类型,而` map ` 多了很多类型,可以是` int ` ,可以是` string ` 及所有完全定义了` == ` 与` != ` 操作的类型。
387
387
388
388
// 声明一个key是字符串,值为int的字典,这种方式的声明需要在使用之前使用make初始化
389
- var numbers map[string] int
389
+ var numbers map[string]int
390
390
// 另一种map的声明方式
391
391
numbers := make(map[string]int)
392
392
numbers["one"] = 1 //赋值
@@ -410,7 +410,7 @@ slice有一些简便的操作
410
410
通过` delete ` 删除` map ` 的元素:
411
411
412
412
// 初始化一个字典
413
- rating := map[string]float32 {"C":5, "Go":4.5, "Python":4.5, "C++":2 }
413
+ rating := map[string]float32{"C":5, "Go":4.5, "Python":4.5, "C++":2 }
414
414
// map有两个返回值,第二个返回值,如果不存在key,那么ok为false,如果存在ok为true
415
415
csharpRating, ok := rating["C#"]
416
416
if ok {
You can’t perform that action at this time.
0 commit comments