map Statement of
var map_variable map[key_data_type]`value_data_type`After declaration map The default value of is nil
map Most of the operations on , Including finding 、 Delete 、len and range The cycle can work safely in nil It's worth it map On , Their behavior and an empty map similar . But to one nil It's worth it map Storing elements will result in a panic abnormal :
golang panic: assignment to entry in nil mapIn the map Before saving data, you must use golang Built in make Function creation map.
map_variable := make(map[key_data_type]value_data_type)If not initialized map, Then create a nil map.nil map Cannot be used to store key value pairs
Combine the above into one sentence
// initialization + Integration of assignment
m := map[string]string{
"a": "aa",
"b": "bb",
}
![洛谷_P1149 [NOIP2008 提高组] 火柴棒等式_枚举打表](/img/4a/ab732c41ea8a939fa0983fec475622.png)







