小编hif*_*iks的帖子

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

让我说我有这个代码:

def dosomething(thing1, thing2=hello, thing3=world):
    print thing1
    print thing2
    print thing3
Run Code Online (Sandbox Code Playgroud)

我希望能够指定什么东西3,但不必说什么东西2.(下面的代码是我认为它可能会起作用的方式......)

dosomething("This says 'hello fail!'", , 'fail!')
Run Code Online (Sandbox Code Playgroud)

它会说

This says 'hello fail!'
hello
fail!
Run Code Online (Sandbox Code Playgroud)

那么有没有办法像这样做,或者我必须指定thing2每次我想说什么thing3

我正在使用python2,如果这很重要.

python

3
推荐指数
1
解决办法
72
查看次数

标签 统计

python ×1