Go delete() 函数


Go delete() 函数

package main



import "fmt"



func main() {   

   /* create a map*/

   countryCapitalMap := map[string] string {"France":"Paris","Italy":"Rome","Japan":"Tokyo","India":"New Delhi"}



   fmt.Println("Original map")   



   /* print map */

   for country := range countryCapitalMap {

      fmt.Println("Capital of",country,"is",countryCapitalMap[country])

   }



   /* delete an entry */

   delete(countryCapitalMap,"France");

   fmt.Println("Entry for France is deleted")  



   fmt.Println("Updated map")   



   /* print map */

   for country := range countryCapitalMap {

      fmt.Println("Capital of",country,"is",countryCapitalMap[country])

   }

}