分三种情况
(以下 “指定返回值”这句话, 仅指return后面直接跟着的返回值)
package main
import (
"fmt"
)
func GetMoney(){
fmt.Println("money")
return
}
func main(){
GetMoney()
}
(2) 函数返回值有变量名
package main
import (
"fmt"
)
func GetMoney() (_amount int){
_amount = 88
fmt.Println("money: ",_amount)
return
}
func main(){
var amount = GetMoney()
fmt.Println("money: ",amount)
}
package main
import (
"fmt"
)
func GetMoney() (_amount int){
fmt.Println("money: ",_amount)
return 88
}
func main(){
var amount = GetMoney()
fmt.Println("money: ",amount)
}
运行结果:
money: 0
money: 88
package main
import (
"fmt"
)
func GetMoney() (_amount int){
_amount = 99
Don't Repeat Yourself !
分三种情况
(以下 “指定返回值”这句话, 仅指return后面直接跟着的返回值)
package main
import (
"fmt"
)
func GetMoney(){
fmt.Println("money")
return
}
func main(){
GetMoney()
}
(2) 函数返回值有变量名
package main
import (
"fmt"
)
func GetMoney() (_amount int){
_amount = 88
fmt.Println("money: ",_amount)
return
}
func main(){
var amount = GetMoney()
fmt.Println("money: ",amount)
}
package main
import (
"fmt"
)
func GetMoney() (_amount int){
fmt.Println("money: ",_amount)
return 88
}
func main(){
var amount = GetMoney()
fmt.Println("money: ",amount)
}
运行结果:
money: 0
money: 88
package main
import (
"fmt"
)
func GetMoney() (_amount int){
_amount = 99
|
请发表评论