当前位置:网站首页>Go language multiple return values and return error types
Go language multiple return values and return error types
2022-07-23 23:15:00 【ydl1128】
go Languages can return multiple values . If I want to return more values , What shall I do? ?
The code is as follows :
func Chen(a int, b int) (int,int) {
if a == 0 || b ==0 {
return 0,0
} else {
return a * b, a*b
}
}
Suppose there is a value error , I want to tell him the reason for the mistake . At this time, you can return values and error objects ,
func Chu(a int, b int) (int,error) {
if b == 0 {
return 0,errors.New(" error !!")
}else {
return a / b,nil
}
}
Test a wave :
func main() {
// Multiple return data
res ,res2 := count.Chen(100, 1)
fmt.Println( res)
fmt.Println( res2)
// Wrong type data
res ,err := count.Chu(1, 0)
if err != nil {
fmt.Println(err)
}
fmt.Println(res)
}
Output results :
100
100
error !!
0
边栏推荐
- [leetcode ladder] linked list · 203 remove linked list elements
- dried food! Implicit sparse regularization effect in neural networks
- Programming in the novel [serial 16] the moon bends in the yuan universe
- Sword finger offer II 115. reconstruction sequence
- [jailhouse article] a novel software architecture for mixed criticality systems (2020)
- About: enable delivery optimization in enterprise LAN
- 汇编语言伪指令详解(附实例)
- Diabetes genetic risk testing challenge advanced
- USB to can device in nucleic acid extractor high performance USB interface can card
- 使用itextpdf提取PDF文件中的任意页码
猜你喜欢

Mobile, telecom and Unicom: fancy solution of 5g to B

TAP 系列文章7 | 易于管理的流水线配置
![[C language] address book (static version)](/img/bc/655c1176e11f66fd168c3fae01bb11.png)
[C language] address book (static version)

Diabetes genetic risk testing challenge advanced

strncat() strncmp()

Mongodb database + graphical tools download, installation and use

Stm32f4 check the frequency of each part of the system

【Unity3D日常BUG】Unity3D解决“找不到类型或命名空间名称“XXX”(您是否缺少using指令或程序集引用?)”等问题

Notes on network segment CIDR

Extract any page number in PDF file with itextpdf
随机推荐
Can Intel NUC replace the host_ It's finally perfect! The latest Intel NUC Mini host comes online
The font of Siyuan notes is thinner and lighter than that in other editors (atom, VSC, sublime)
[web vulnerability exploration] SQL injection vulnerability
浅析基于NVR技术的视频能力与未来发展趋势
Matlab Foundation
Open source embedded sig in the openeuler community. Let's talk about its multi OS hybrid deployment framework
Data sorting and usage before torchvision.datasets.imagefolder
Contemporary inspirational "women"
Rosbag file recorded by LIDAR point cloud data is converted into CSV file
(CVPR-2022)BiCnet
STM32F4查看系统各部分频率
激光雷达点云数据录制的rosbag文件转换成csv文件
USB转CAN设备在核酸提取仪 高性能USB接口CAN卡
[jailhouse article] a novel software architecture for mixed criticality systems (2020)
[leetcode ladder] the penultimate node in the 022 linked list
Series of articles | the way to advance the microservice architecture in the cloud native era - best practices of microservice splitting
Analysis of mobile semantics and perfect forwarding
Relevant interfaces of [asp.net core] option mode
Lixia action 2022 Yuanqi digital round table forum will be launched soon
Redis pipeline technology / partition