Python Lambda函数可选变量

时间:2018-07-17 11:18:34

标签: python python-3.x lambda

substring = lambda s,start=0,end=len(s) : s[start:end]
print(substring("python",1))

我收到一条错误消息,说未定义s

NameError                                 Traceback (most recent call last)
<ipython-input-18-7e4b2c9c6d67> in <module>()
----> 1 substring = lambda s,start=0,end=len(s) : s[start:end]
      2 print(substring("python",1,3))

 NameError: name 's' is not defined 

我想将开始和结束作为可选变量。我该怎么办?

0 个答案:

没有答案