python 错误之TypeError: XXXXX() takes no keyword arguments


举个例子:

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM