相关疑难解决方法(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万
查看次数

位置参数跟随关键字参数

我在python中调用这样的函数.

order_id = kite.order_place(self, exchange, tradingsymbol, 
transaction_type, quantity, price, product, order_type, validity, 
disclosed_quantity=None, trigger_price=None, squareoff_value, 
stoploss_value, trailing_stoploss, variety, tag='')
Run Code Online (Sandbox Code Playgroud)

这是函数文档中的代码..

def order_place(self, exchange, tradingsymbol, transaction_type, 
quantity, price=None, product=None, order_type=None, validity=None, 
disclosed_quantity=None, trigger_price=None, squareoff_value=None, 
stoploss_value=None, trailing_stoploss=None, variety='regular', tag='')
Run Code Online (Sandbox Code Playgroud)

它给出了这样的错误..

在此输入图像描述

如何解决此错误?谢谢 !

python

9
推荐指数
1
解决办法
7万
查看次数

标签 统计

python ×2