✨Feat: 多返回值函数
This commit is contained in:
@@ -13,8 +13,14 @@ func add2(x, y int) int {
|
|||||||
return x + y
|
return x + y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func swap(x, y string) (string, string) {
|
||||||
|
return y, x
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("You know Pi =", math.Pi)
|
fmt.Println("You know Pi =", math.Pi)
|
||||||
fmt.Println("And You know 1+2 =", add(1, 2))
|
fmt.Println("And You know 1+2 =", add(1, 2))
|
||||||
fmt.Println("And You know 1+2 =", add2(1, 2), "Using syntax sugar")
|
fmt.Println("And You know 1+2 =", add2(1, 2), "Using syntax sugar")
|
||||||
|
a, b := swap("hello", "world")
|
||||||
|
fmt.Println("And You know swap('hello', 'world') =", a, b)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user