舉個例子:
str1 = 'sunlightn' f = str1.rfind("n", __start=1, __end=2) print(f)
以上代碼運行后出現:
"D:\Program Files\Python\Python37-32\python.exe" D:/demo/str_1.py Traceback (most recent call last): File "D:/demo/str_1.py", line 147, in <module> f = str1.rfind("n", __start=1, __end=2) TypeError: rfind() takes no keyword arguments Process finished with exit code 1
意思是 rfind()方法不接受關鍵字參數,而代碼中又使用了關鍵字參數
修改為位置參數后正常運行
str1 = 'sunlightn' f = str1.rfind("n", 1, 2) print(f) "D:\Program Files\Python\Python37-32\python.exe" D:/demo/str_1.py -1 Process finished with exit code 0