golang rsa密钥_如何在Golang的地图中检查密钥是否存在?
golang rsa密鑰
When you try to get the value of key in a map, you get two return values. The first value is the value of key and second is bool value which could be either true or false. If a key is present in the map then the second value will be true else false.
當您嘗試獲取映射中的key值時,您將獲得兩個返回值。 第一個值是key的值,第二個值是bool值,可以為true或false。 如果映射中存在鍵,則第二個值將為true,否則為false 。
If a key is not present in the map then the first value will be default zero value.
如果映射中不存在鍵,則第一個值為默認的零值。
Syntax:
句法:
first_value, second_value := map_variable_name[key_name]orfirst_value := map_variable_name[key_name]orfirst_value, _ := map_variable_name[key_name]Here, second_value is optional.
在這里, second_value是可選的。
Code example:
代碼示例:
package mainimport ("fmt" )func main() {m:= map[string]int{"apple": 1}value, ok := m["apple"]fmt.Println(value, ok)value, ok = m["mango"]fmt.Println(value, ok) }Output
輸出量
1 true 0 falseCheck key exists in map using if-statement
使用if語句在地圖中檢查密鑰是否存在
package mainimport ("fmt" )func main() {m:= map[string]int{"apple": 1}if value, ok := m["apple"]; ok {fmt.Printf("Apple is present in map. Value is: %d\n", value)} else {fmt.Printf("Apple is not present in map. Value is: %d\n", value)}if value, ok := m["mango"]; ok {fmt.Printf("Mango is present in map. Value is: %d\n", value)} else {fmt.Printf("Mango is not present in map. Value is: %d\n", value)} }Output
輸出量
Apple is present in map. Value is: 1 Mango is not present in map. Value is: 0翻譯自: https://www.includehelp.com/golang/how-to-check-if-key-exists-in-a-map-in-golang.aspx
golang rsa密鑰
總結
以上是生活随笔為你收集整理的golang rsa密钥_如何在Golang的地图中检查密钥是否存在?的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 为什么Spring需要三级缓存解决循环依
 - 下一篇: 将所有文件从目录复制到Python中的另