如何找出函数参数为空

时间:2017-01-04 09:27:18

标签: python

我想创建一个函数相同的range(),例如func_range(),它有三个参数 func_range(开始,结束,步骤)但是当调用没有参数的函数时我想打印例如“请设置参数”。

我怎样才能检查函数

中是否存在参数
npm install -g cordova

2 个答案:

答案 0 :(得分:0)

为参数提供默认值,或者您可以使用args keyword

>>> def f(start=None, end=None, step=None):
...     if (start == None and end == None and step == None):
...             print("please set the argument")
...     else:
...             pass #do whatever you wish
... 
>>> f()
please set the argument

答案 1 :(得分:0)

您可以使用以下可选参数:

DB::table('Mytable')->where('col1','value')
    ->groupBy(function($date) {
        return Carbon::parse($date->Date_time)->format('m'); // grouping by months
    })
    ->count();
相关问题