我正在这里阅读教程:http://www.newthinktank.com/2015/02/go-programming-tutorial/
在“地图中的地图”部分有:
package main
import "fmt"
func main() {
// We can store multiple items in a map as well
superhero := map[string]map[string]string{
"Superman": map[string]string{
"realname":"Clark Kent",
"city":"Metropolis",
},
"Batman": map[string]string{
"realname":"Bruce Wayne",
"city":"Gotham City",
},
}
// We can output data where the key matches Superman
if temp, hero := superhero["Superman"]; hero {
fmt.Println(temp["realname"], temp["city"])
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白“如果”语句。有人可以引导我完成这一行的语法吗:
if temp, hero := superhero["Superman"]; hero {
Run Code Online (Sandbox Code Playgroud)
if temp
对于局外人来说,这似乎是荒谬的,因为 temp 甚至没有在任何地方定义。那会实现什么?然后hero := superhero["Superman"]
看起来像是一个任务。但是分号是做什么的呢?为什么决赛hero
在那里?
有人可以帮助新手吗?
非常感谢。
如果我在函数中声明一个变量或参数,大写是否有任何影响或意义?
显然,对于函数之外的方法和变量,它会导出它们,但是上面的呢?