Insert or update an element in map m:

m[key] = elem

Retrieve an element:

elem = m[key]

Delete an element:

delete(m, key)

Test that a key is present with a two-value assignment:

elem, ok = m[key]

If key is in mok is true. If not, ok is false and elem is the zero value for the map's element type.

Similarly, when reading from a map if the key is not present the result is the zero value for the map's element type.

package main
import "fmt" func main() {
m := make(map[string]int) m["Answer"] =
fmt.Println("The value:", m["Answer"]) m["Answer"] =
fmt.Println("The value:", m["Answer"]) v, ok := m["Answer"]
fmt.Println("The value:", v, "Present?", ok) delete(m, "Answer")
fmt.Println("The value:", m["Answer"]) v2, ok2 := m["Answer"]
fmt.Println("The value:", v2, "Present?", ok2)
}

好变态的map用法,真不知道google是怎怎么想的

A Tour of Go Mutating Maps的更多相关文章

  1. A Tour of Go Exercise: Maps

    Implement WordCount. It should return a map of the counts of each “word” in the string s. The wc.Tes ...

  2. Essential controls for web app

    AUTO-COMPLETE/AUTO-SUGGEST Auto-complete using Vaadin Offer auto-suggest or auto-complete to help yo ...

  3. A Tour of Go Maps

    A map maps keys to values. Maps must be created with make (not new) before use; the nil map is empty ...

  4. exercise.tour.go google的go官方教程答案

    /* Exercise: Loops and Functions #43 */ package main import ( "fmt" "math" ) fun ...

  5. go官网教程A Tour of Go

    http://tour.golang.org/#1 中文版:http://go-tour-cn.appsp0t.com/#4 package main import ( "fmt" ...

  6. Go structs、slices、maps

    [Go structs.slices.maps] 1.定义时*在变量名后面,使用时*在变量名前面. 2.定义struct,type在前,struct关键字在后. 3.指针可以指定struct. 4.A ...

  7. 动态规划:HDU1224-Free DIY Tour

       Free DIY Tour Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. Hdu 3488 Tour (KM 有向环覆盖)

    题目链接: Hdu 3488 Tour 题目描述: 有n个节点,m条有权单向路,要求用一个或者多个环覆盖所有的节点.每个节点只能出现在一个环中,每个环中至少有两个节点.问最小边权花费为多少? 解题思路 ...

  9. 检索Google Maps地图位置(小训练)

    名称:检索地图位置 内容:地图初期显示和检索显示 功能:根据条件检索地图的经度与纬度 1.在这之前我们需要创建一个表(Accoun__c),添加一个重要的字段地理位置情報,它会默认的给你两个字段经度和 ...

随机推荐

  1. 【BZOJ 1046】 1046: [HAOI2007]上升序列

    1046: [HAOI2007]上升序列 Description 对于一个给定的S={a1,a2,a3,-,an},若有P={ax1,ax2,ax3,-,axm},满足(x1 < x2 < ...

  2. c++ 基础学习: 左值 概念cocos2d-x3.0的实际应用

    左值:概念baidu 1.2.6.2 与Cocos2d-x内存管理的结合 在2.x的使用场景中,CCArray和CCDictionary通常被分配在堆上,我们不得不需要考虑在适当的地方释放其内存.新的 ...

  3. UPDATE和SELECT嵌套使用

    1 2 update a set HIGH=b.NEW  from SPEC1 a,tmpDOT  b  where a.high=b.old

  4. node.js模块值formidable

    模块地址:https://github.com/felixge/node-formidable var formidable = require('formidable'), http = requi ...

  5. 利用VC/VS的安装目录找到C/C++库函数实现的源代码

    2013-07-03 20:08:57 大多开发软件的装目录下都有很多有价值的东西,比如help文档.user guide.src文件等.今天在VS的安装目录下发现了库函数的源文件,这些文件中有对所有 ...

  6. 普通方式 分页【NOT IN】和【>】效率大PK 千万级别数据测试结果

    首现创建一张表,然后插入1000+万条数据,接下来进行测试. use TTgoif exists (select * from sysobjects where name='Tonge')drop t ...

  7. Windows 下目录及文件向Linux同步

    本文解决的是Windows 下目录及文件向Linux同步的问题,Windows向 Windows同步的请参考:http://www.idcfree.com/article-852-1.html 环境介 ...

  8. Gen_fsm行为实践与分析

    1.简介 Gen_fsm是一个通用的有限状态机,它描述了这样的一组关系: State(S) x Event(E) -> Actions(A),State(S') 这个关系意味着:如果在S状态下发 ...

  9. 工作流设计 zt

    工作流设计 业务流程管理模块是本平台的重要组成部分,要实现将已经发布的标准中规范化的流程转化为具体计算机中的流程从而实现流程的自动运转,将标准化成果与员工的日常工作紧密结合起来,具有重要意义. 业务流 ...

  10. 44、网页启动Activity,网页传值Activity

         在assets新建一个demo.html 文件. <html> <head> <meta http-equiv="Content-Type" ...