当前位置:网站首页>Self study golang [3.7map exercise code]
Self study golang [3.7map exercise code]
2022-07-22 08:35:00 【Aspire to be a doctor】
map Practice code for :
package main
import "fmt"
func main() {
m := map[string]string{ // Define a map
"name": "lwj",
"course": "golang",
"site": "im",
"quality": "good",
}
m2 := make(map[string]int) // Define an empty map.m2==empty map
var m3 map[string]int // Define an empty map, Same as m2 equally .m3==nil
fmt.Println(m, m2, m3)
fmt.Println("map The traversal :")
for k, v := range m { // The order of output is out of order
fmt.Println(k, v)
}
fmt.Println(" obtain map A variable value of :")
coursename := m["course"] //course If the input is wrong, a blank will be output
fmt.Println(coursename)
// Prevent the variable value from nonexistence
if causename, ok := m["cause"]; ok { // Judge whether the value exists
fmt.Println(causename)
} else {
fmt.Println(" Keywords don't exist ")
}
fmt.Println(" Delete map A variable value of :")
name, ok := m["name"]
fmt.Println(name, ok)
delete(m, "name")
name, ok = m["name"]
fmt.Println(name, ok)
}
Running results :
map The traversal :
course golang
site im
quality good
name lwj
obtain map A variable value of :
golang
Keywords don't exist
Delete map A variable value of :
lwj true
false
边栏推荐
- Redis' classic three questions and sentinel
- 自学golang【3.7map的练习代码】
- 自学golang【3.4go语言的函数和指针】定义一个函数返回一个或多个值,go语言的指针,指针不能运算,go语言参数传递只有值传递,通过指针实现地址传递,函数返回2个值,如何只接受一个值
- 软考中级【数据库系统工程师】第0章:如何自学备考,考试介绍考什么,备考教材,上午和下午的体型分数分布,备考课程链接,个人备考感谢
- C语言指针和数组a与&a,&a[0]等的区别
- 量化交易中的三类行情
- Verilog应用——24秒篮球计数器
- Sum the numbers in the region using the sum function
- How does idea import automatically
- 科技创造价值 | 云扩科技荣登真榜·中国科技创新品牌榜TOP100
猜你喜欢
Find the same name in both spreadsheets
地址总线、数据总线、控制总线详细解释
自学golang【3.6切片slice的练习代码】切片的长度,上限,复制,删除与增加
张驰咨询:某包装印刷集团第五期六西格玛项目通过专家评审
excel 隐藏和取消隐藏
Sharing the ultimate breakthrough strategy used by professional traders for many years (with a full set of trading templates)
Analysis of location cache module and detailed explanation of OCP monitoring and alarm
Pytorch学习(一).深度学习回顾和Pytorch简介
WebSockets and server sent events
Detailed construction process of airflow (personal test + summary)
随机推荐
Detailed construction process of airflow (personal test + summary)
自学golang【3.2go语言变量的类型与条件语句,常量,变量,枚举,if语句与switch语句的应用】
Error: L6200E: Symbol keyflag multiply defined (by main.o and key.o).
一个交易系统需要经过几年的考验才算成功的交易系统,盈利需要几年才算稳定?
How does idea import automatically
云安全日报220721:思科混合云运维管理解决方案发现执行任意命令漏洞,需要尽快升级
量化交易中的三类行情
Redis' classic three questions and sentinel
excel 如何删除有颜色的行
Can you do application development without programming? Yes!
STM32 HAL库 SPI总是读出FF的问题解决!
使用 SUM 函数对区域中的数字求和
C语言中逗号表达式的使用
Module loader implementation of no.js
自学golang【3.3go语言的循环语句】for循环语法结构,省略初始条件,省略递增条件,省略结束条件的应用
Activiti default model ER diagram
Spark read CSV file operation, explanation of option parameter
excel中怎么批量在文字前后增加文字
深度学习之Caffe框架及制作数据源
十年交易员重磅推荐:简单易操作的突破回调策略