相关疑难解决方法(0)

为什么非默认参数不能遵循默认参数?

为什么这段代码会抛出一个SyntaxError?

  >>> def fun1(a="who is you", b="True", x, y):
...     print a,b,x,y
... 
  File "<stdin>", line 1
SyntaxError: non-default argument follows default argument
Run Code Online (Sandbox Code Playgroud)

虽然下面的代码运行没有可见的错误:

>>> def fun1(x, y, a="who is you", b="True"):
...     print a,b,x,y
... 
Run Code Online (Sandbox Code Playgroud)

python

118
推荐指数
3
解决办法
13万
查看次数

目前该函数应该采用 1 个必需参数和 2 个选项......如何解决?

目前该函数应该采用 1 个必需参数和 2 个可选参数,但是代码不起作用。修复代码,使其通过测试。这应该只需要更改一行代码。

def waste(var = "Water", mar, marble = "type"):
    final_string = var + " " + marble + " " + mar
    return final_string
Run Code Online (Sandbox Code Playgroud)

SyntaxError:非默认参数遵循第 2 行的默认参数我更改了很多时间修复它但没有结果谢谢!

python keyword

2
推荐指数
1
解决办法
892
查看次数

标签 统计

python ×2

keyword ×1