请教一个py关键字参数问题

ss = '012345.78'
print(ss.endswith('.', 1, 7))

结果是True,没有疑问~~

但是我无意中用了关键字参数传递
ss.endswith('.', start=1, end=7)
ss.endswith('.', 1, end=7)

**没想到都抛异常
TypeError: endswith() takes no keyword arguments**

请问是什么原因?

慕后森
浏览 644回答 1
1回答

收到一只叮咚

本来 endswith() 就没有 start 和 end 参数,它的函数原型是这样的 Docstring: S.endswith(suffix[, start[, end]]) -> bool Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try. Type: builtin_function_or_method 只有函数原型是 endswith(suffix, start=0, end=-1) 或者 endswith(suffix, **kwargs) 时,才可以使用 endswith(xx, start=N, end=M) 方式调用。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python