当前位置:网站首页>Go language mapping operation
Go language mapping operation
2022-04-23 12:56:00 【Play ha ha 527】
package main
import "fmt"
// Creating and using maps
func main() {
// Create a map , The type of bond is string, The type of value is int
dict:=make(map[string]int)
fmt.Println(dict)
// Create a map , The types of keys and values are string
// Initialize the mapping with two key value pairs
dict1:=map[string]string {
"apple":"good","orange":"bad"}
fmt.Println(dict1)
// Create a map , You cannot use string slices as keys for mapping , But you can use slices as values
//dict2:=map[string[]]int{}// Compile error
dict2:=map[string][]string{
}
dict3:=map[int][]string{
}
fmt.Println(dict2)
fmt.Println(dict3)
// Use range Iterative mapping , Return key value pair
// Create a map
dict4:=map[string]int{
"a":1,"b":2,"c":3,"d":4}
fmt.Println(dict4)
for key,value:=range dict4{
fmt.Printf("key:%s value:%d\n",key,value)
}
// Determine whether there are key value pairs
var str string="s"
value,exists:=dict4[str]
if exists {
fmt.Printf(" There are keys %s Match value of , Its value is %d\n",str,value)
}else
{
fmt.Printf(" There is no bond %s Match value of \n",str)
}
delete(dict4,"a")// Delete a key value pair
fmt.Println(dict4)
// Transfer mapping between functions
ss:=map[string]int{
"s1":1,"s2":2,"s3":3,"s4":4}
fmt.Println(ss)
ss1:=Remove(ss)
fmt.Println(ss1)
}
func Remove(ss map[string]int) map[string]int {
delete(ss,"s1")
return ss
}
/* Output results map[] map[apple:good orange:bad] map[] map[] map[a:1 b:2 c:3 d:4] key:a value:1 key:b value:2 key:c value:3 key:d value:4 There is no bond s Match value of map[b:2 c:3 d:4] map[s1:1 s2:2 s3:3 s4:4] map[s2:2 s3:3 s4:4] */
版权声明
本文为[Play ha ha 527]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230615231468.html
边栏推荐
- 如何实现点击一下物体播放一次动画
- Buuctf Web [gxyctf2019] no dolls
- C, calculation code of parameter points of two-dimensional Bezier curve
- php生成json处理中文
- BUUCTF WEB [BJDCTF2020]The mystery of ip
- Record the problems encountered in using v-print
- 【蓝桥杯】4月17日省赛刷题训练(前3道题)
- Record Alibaba cloud server mining program processing
- 0基础可以考CPDA数据分析师证书吗
- 只是不断地建构平台,不断地收拢流量,并不能够做好产业互联网
猜你喜欢

Huawei cloud MVP email

Record some NPM related problems (messy records)

标签与路径

航芯技术分享 | ACM32 MCU安全特性概述
![[csnote] ER diagram](/img/97/82e8c2183fcafda50950a953ca0955.png)
[csnote] ER diagram

What are the forms of attack and tampering on the home page of the website

Plato farm - a game of farm metauniverse with Plato as the goal

大家帮我看一下这是啥情况,MySQL5.5的。谢了

STM32 control stepper motor (ULN2003 + 28byj)

云原生KubeSphere部署Redis
随机推荐
Jiachen chapter Genesis "inner universe" joint Edition
RT-thread中关键词解释及部分API
Resolve disagrees about version of symbol device_ create
Object. The disorder of key value array after keys
4.DRF 权限&访问频率&过滤&排序
教你快速开发一个 狼人杀微信小程序(附源码)
Embrace the new blue ocean of machine vision and hope to open a new "Ji" encounter for the development of digital economy
Record Alibaba cloud server mining program processing
世界读书日:我想推荐这几本书
NPDP|产品经理如何做到不会被程序员排斥?
V-model binding value in El select, data echo only displays value, not label
标签与路径
Plato farm - a game of farm metauniverse with Plato as the goal
Unlock openharmony technology day! The annual event is about to open!
mysql中 innoDB执行过程分析
The accuracy and speed are perfectly balanced, and the latest image segmentation SOTA model is released!!!
mysql8安装
Can I take the CPDA data analyst certificate for 0 foundation
Zigbee之CC2530最小系统及寄存器配置(1)
Kubernets Getting started tutoriel