Advertisement
cwchen

[Go] Default value for non-existing key in map.

Sep 23rd, 2017
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.26 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "log"
  5. )
  6.  
  7. func main() {
  8.     m := make(map[string]string)
  9.  
  10.     m["Go"] = "Beego"
  11.     m["Python"] = "Django"
  12.     m["Ruby"] = "Rails"
  13.     m["PHP"] = "Laravel"
  14.  
  15.     // No such key/value pair.
  16.     if !(m["Java"] == "") {
  17.         log.Fatal("Wrong value")
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement