在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python  Linux/ 請教一個py關鍵字參數(shù)問題

請教一個py關鍵字參數(shù)問題

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

結果是True,沒有疑問~~

但是我無意中用了關鍵字參數(shù)傳遞
ss.endswith('.', start=1, end=7)
ss.endswith('.', 1, end=7)

**沒想到都拋異常
TypeError: endswith() takes no keyword arguments**

請問是什么原因?

回答
編輯回答
毀憶

本來 endswith() 就沒有 startend 參數(shù),它的函數(shù)原型是這樣的

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

只有函數(shù)原型是
endswith(suffix, start=0, end=-1)
或者
endswith(suffix, **kwargs)
時,才可以使用 endswith(xx, start=N, end=M) 方式調用。

2018年3月14日 04:55