如何在python中不提供所有默认参数?

2024-04-19 00:07:26 发布

您现在位置:Python中文网/ 问答频道 /正文

假设我有以下代码:

def dosomething(thing1, thing2=hello, thing3=world):
    print thing1
    print thing2
    print thing3

我想能够具体说明什么是thing3,但不必说什么是thing2。(下面的代码是我认为它是如何工作的…)

dosomething("This says 'hello fail!'", , 'fail!')

它会说

This says 'hello fail!'
hello
fail!

那么有没有这样的方法,或者每次我想说thing3是什么时,我都必须指定thing2?你知道吗

我在用Python2,如果有关系的话。你知道吗


Tags: 方法代码helloworld关系defthisfail