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