dart的函数定义如下所示
// Define a function.
printInteger(int aNumber) {
print('The number is $aNumber.'); // Print to console.
}
// This is where the app starts executing.
main() {
var number = 42; // Declare and initialize a variable.
printInteger(number); // Call a function.
}
isNoble(atomicNumber) {
return _nobleGases[atomicNumber] != null;
}
如果函数只有单个语句,可以采用简略的形式:
bool isNoble(int atomicNumber) => _nobleGases[atomicNumber] != null;
$dart取地址
String say(String from, String msg, [String device]) {
var result = '$from says $msg';
if (device != null) {
result = '$result with a $device';
}
return result;
}
以分号结尾 参数类型要指定也可以不指定
=> 是{ return expr;} 的缩写
oc的函数定义
-(void)hello{
print(@"hello world");
}
-(void)hello(int a,int b){
print(@"hello world %d %d",a,b);
}
无需注意缩进 但是返回值类型一定要明确
python函数定义
def xxxx:
print 'hello world'
def xxx(a,b):
print(a,b)
def xxx(self,a,b)
print a,b
由于没有分号和大括号所以一定要注意缩进,