[英]How to skip the parameters of a function in python?
I am trying to skip parameters while calling a function. Could you please help me how to do this?我在调用 function 时试图跳过参数。你能帮我怎么做吗?
Example:例子:
I have to call below function which is having 3 parameters:我必须在下面调用 function,它有 3 个参数:
send_mail(audit_df, LOG_FILE, Duration)
I have to call above function to skip 1st and 3rd parameters.我必须调用上面的 function 来跳过第一个和第三个参数。 How can i do this?我怎样才能做到这一点?
You can setup default values for the parameters.您可以为参数设置默认值。 I don't know what works for you, so I just set them to None
.我不知道什么对你有用,所以我只是将它们设置为None
。
def send_mail(audit_df=None, log_file=None, duration=None):
do all the things
when calling打电话的时候
send_mail(log_file="myfile")
For a little light reading see the Function definitions section of the docs.如需简单阅读,请参阅文档的Function 定义部分。
You can place "None" in place of the parameter.您可以放置“无”来代替参数。
This is going to make python assume that it is Nothing and will do nothing.这将使 python 假设它是 Nothing 并且什么都不做。
This can be done in two ways using这可以通过两种方式使用
See the answer below for details详情请看下面的回答
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.