当前位置:网站首页>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
边栏推荐
- 标签与路径
- SSM framework series - JUnit unit test optimization day2-3
- SSM框架系列——Junit单元测试优化day2-3
- Plato farm - a game of farm metauniverse with Plato as the goal
- 网站首页文件被攻击篡改的形式有哪些
- Get the punch in record of nailing attendance machine
- [Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
- BUUCTF WEB [BJDCTF2020]The mystery of ip
- Homomorphic encryption technology learning
- 4.DRF 权限&访问频率&过滤&排序
猜你喜欢
【每日一题】棋盘问题
CVPR 2022&NTIRE 2022|首个用于高光谱图像重建的 Transformer
解决disagrees about version of symbol device_create
XinChaCha Trust SSL Organization Validated
mysql8安装
航芯技术分享 | ACM32 MCU安全特性概述
STM32 control stepper motor (ULN2003 + 28byj)
SSM框架系列——Junit单元测试优化day2-3
Softbank vision fund entered the Web3 security industry and led a new round of investment of US $60 million in certik
Use compressorjs to compress pictures, optimize functions, and compress pictures in all formats
随机推荐
How to click an object to play an animation
Free and open source charging pile Internet of things cloud platform
The quill editor image zooms, multiple rich text boxes are used on one page, and the quill editor upload image address is the server address
进程虚拟地址空间区域划分
8 websites that should be known for product development to enhance work experience
Baserecyclerviewadapterhelper realizes pull-down refresh and pull-up loading
Record some NPM related problems (messy records)
Ad20 supplementary note 3 - shortcut key + continuous update
BUUCTF WEB [BJDCTF2020]The mystery of ip
V-model binding value in El select, data echo only displays value, not label
Deploying MySQL in cloud native kubesphere
What are the forms of attack and tampering on the home page of the website
Try the server for one month for free, and attach the tutorial
Mysql8 installation
SSM框架系列——Junit单元测试优化day2-3
C, calculation code of parameter points of two-dimensional Bezier curve
CVPR 2022&NTIRE 2022|首个用于高光谱图像重建的 Transformer
Object. The disorder of key value array after keys
Record the problems encountered in using v-print
Object.keys后key值数组乱序的问题