函数的定义及调用
func开头作为前缀,->返回的类型
add输出结果是11
函数参数也可以有多个参数,写在括号里用逗号隔开。
func introduce(name: String,age: Int) -> String
{
return "\(name),I'm \(age) year old now."
}
introduce("Zing",)
无参函数
func helloWorld()
{
return "hello world"
}
print(helloWorld())
多重返回值函数
func operation(pending: Int...) ->(add: Int,ride: Int)
{
var ad = ,ri =
for a in add
{
ad+=a
}
for r in ride
{
ri*=r
}
return (ad,ri)
}
let result = operation(,,)
print("加\(result.add),乘\(result.ride)")