举个例子:
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