»
07. if
Go语言中的条件判断也使用if-else,但是,Go语言中if判断句可以有两个,其中,后面的一个语句起作用:
if _, exists := book_id_map['Route of go learning']; exists {//book_id_map为map[string]int
fmt.Println('Exists. this book's id is ' + book_id_map['Route of go learning'])
} else {
fmt.Println('Not Exists')
}
以上的代码也可以用下面的代码代替,这是if语句中的相同用法:
if id, exists := book_id_map['Route of go learning']; exists {//book_id_map为map[string]int
fmt.Println('Exists. this book's id is ' + id)
} else {
fmt.Println('Not Exists')
}
————www.v-signon.com学习者共勉