当前位置:网站首页>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
边栏推荐
- Stm32f4 check the frequency of each part of the system
- Extract any page number in PDF file with itextpdf
- [in depth study of 4g/5g/6g topic -40]: urllc-11 - in depth interpretation of 3GPP urllc related protocols, specifications and technical principles -5-5g QoS principle and Architecture: slicing, PDU s
- Merge.Avhd into.Vhd manually in Hyper-V
- [Matplotlib drawing]
- The ultimate experiment of OSPF -- learn the example of OSPF century template
- Rails with OSS best practices
- As a developer, you have to know the three performance testing tools JMeter, API and jmh user guide
- Upgrade unity visual studio 2019 to 2022 (throw away pirated red slag)
- YOLOv4: Optimal Speed and Accuracy of Object Detection
猜你喜欢

FL Studio 20.9 update Chinese version host Daw digital audio workstation

Tap series article 5 | cloud native build service

(CVPR-2022)BiCnet

1000 okaleido tiger launched binance NFT, triggering a rush to buy

Array - 11. Containers with the most water

J9 number theory: how can we overcome the fomo phenomenon in the digital industry?

Smart IOT source code with configuration IOT source code industrial IOT source code: support sensor analysis services, real-time data collection and remote control
![[leetcode ladder] linked list · 203 remove linked list elements](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[leetcode ladder] linked list · 203 remove linked list elements

torchvision.datasets.ImageFolder前的数据整理及使用方法

浅析基于NVR技术的视频能力与未来发展趋势
随机推荐
ospf终极实验——学会ospf世纪模板例题
Is the height of binary tree [log2n]+1 equal to log2 (n+1)
ES6 use of arrow function
Rails搭配OSS最佳实践
Mongodb - Introduction to the use of $exists and the combination of $ne, $nin, $nor, $not in query statements
Lin Zhiying's injury is relatively stable
About synchronizing data from computer to mobile
TAP 系列文章6 | TAP的应用模型
浅析基于NVR技术的视频能力与未来发展趋势
[leetcode ladder] linked list · 203 remove linked list elements
Internet协议栈 TCP/IP模型 物理层、链路层、网络层、传输层、应用层的作用
Array -- 27. remove elements
ES6 other syntax and extended syntax summary
礪夏行動|源啟數字化:既有模式,還是開源創新?
Preparation for raspberry pie 3B serial port login
Tap series article 5 | cloud native build service
SOLIDWORK learning notes: Sketch geometric relationships and editing
Introduction to mysqlbinlog command (remote pull binlog)
QT set cache and compile output path
Getting started database days2