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有一些简便的操作
386386我们看下面的代码,` map ` 的读取和设置也类似` slice ` 一样,通过` key ` 来操作,只是` slice ` 的` index ` 只能是`int`类型,而` map ` 多了很多类型,可以是` int ` ,可以是` string ` 及所有完全定义了` == ` 与` != ` 操作的类型。
387387
388388 // 声明一个key是字符串,值为int的字典,这种方式的声明需要在使用之前使用make初始化
389- var numbers map[string] int
389+ var numbers map[string]int
390390 // 另一种map的声明方式
391391 numbers := make(map[string]int)
392392 numbers["one"] = 1 //赋值
@@ -410,7 +410,7 @@ slice有一些简便的操作
410410通过` delete ` 删除` map ` 的元素:
411411
412412 // 初始化一个字典
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 }
414414 // map有两个返回值,第二个返回值,如果不存在key,那么ok为false,如果存在ok为true
415415 csharpRating, ok := rating["C#"]
416416 if ok {
You can’t perform that action at this time.
0 commit comments