简体   繁体   English

有什么方法可以无序使用默认参数,而不必在Python函数中显式传递它们?

[英]Is there any way to use default parameters out of order without having to pass them explicitly in a Python function?

For example, I have this function: 例如,我有以下功能:

def do_something(a=None, b=None, c=None):
    pass

Let's say I want to pass only the last parameter to this function, so the call of this function would be like this: do_something(None, None, 15) . 假设我只想将最后一个参数传递给此函数,所以此函数的调用将像这样: do_something(None, None, 15) Is there anyway to do this without passing the first two parameters explicitly? 无论如何,没有显式地传递前两个参数就可以做到这一点?

是的,只是发出

do_something(c=15)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法在python中执行文件中的所有函数而不显式调用它们? - Is there a way in python to execute all functions in a file without explicitly calling them? 有没有办法在 Python 中传递一个块参数而不首先将其定义为 function? - Is there any way to pass a block argument in Python without defining it as a function first? Python:显式使用默认参数 - Python: explicitly use default arguments 使用默认参数传入函数 - Pass in function with default parameters 将多个参数传递给python中的函数的方法 - Way to pass multiple parameters to a function in python python如何将多个参数传递给类而不需要它们 - python how to pass multiple parameters to class without making them required Python Pandas:聚合大型列子集,而无需显式键入它们 - Python Pandas: aggregate large subset of columns without explicitly typing them out Python将带有参数的函数作为参数传递给高阶函数? - Python pass function with parameters as parameter to higher order function? 如何在类中的函数中使用 append 和 extend 而不在同一个类中显式定义它们? - How to use append and extend in a function within a class without explicitly defining them in the same class? 有没有办法传递一个需要 args 的函数,而不需要 args 并在以后添加它们? - Is there a way to pass a function that requires args, without args and add them later?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM