python報錯string python報錯彙總

2021-10-16 21:23:42 字數 1743 閱讀 2079

(most recent call last): file

「e:/pycharm/pythonbase/day01/02_變數.py」, line 12, in

print (name+age+hobby) typeerror: must be str, not int 型別錯誤:必須是字串,不能是整數型

解決方法:將整數型前邊加上str,轉化為字串型別

print(1,2,3,4,5,sep=』-』)

^ indentationerror: unexpected indent 縮排錯誤:意外縮排

解決:將print頂格/或4個空格

typeerror: must be str, not int

錯誤型別:此處5是int型

解決方法:print(『我本來有5元,現在一共有』,str(5)+money,『元』)注意:

1.print(『我本來有5元,現在一共有』,str(5)+money,『元』)

輸出:我本來有5元,現在一共有 5**(字串拼接) 元2.print(『我本來有5元,現在一共有』,『str(5)+money』,『元』)

輸出:我本來有5元,現在一共有 str(5)+money(不會對內容拼接,直接顯示引號中的內容) 元

typeerror: unsupported operand type(s) for +: 『int』 and 『str』

錯誤型別:此處money是字串

數字後面跟+,預設是做數**算

解決方法:print(『我本來有5元,現在一共有』,5+int(money),『元』)

valueerror: could not convert string to float: 『1+1』

錯誤型別:1+1 不能由字串轉變為浮點型數值(原因:+號不能轉換)

解決方法:輸入浮點型數值

indexerror: list index out of range

錯誤型別:

索引錯誤:超出列表的索引範圍(下標太大)

解決方法:更改下標 或 增添索引的範圍即新增內容

a[0]=『h』

typeerror: 『str』 object does not support item assignment

錯誤型別:字串物件不支援專案分配

b[0]=『h』

typeerror: 『tuple』 object does not support item assignment

錯誤型別:元組物件不支援專案分配

typeerror: myprint() missing 1 required positional argument: 『x』

錯誤型別:函式xmyprint缺失 執行所需的函式x 的值

解決方法: 新增x 的函式

attributeerror: 『person』 object has no attribute 『score』

屬性錯誤:某個隊形(person)缺失某個屬性(score)

解決方法:新增屬性

typeerror: write() argument must be str, not int

valueerror: i/o operation on closed file.

value錯誤:i/o 操作在關閉的檔案上

檔案被**關閉,無法再寫入

解決方法:將**放置 file.close()函式之前

permissionerror: [errno 13] permission denied: 『newexcel.xls』

python引數報錯 python 報錯資訊彙總

1.userwarning data validation extendion is not supported and will be removed 可能原因 第三方包與當前python版本不匹配,有部分擴充套件功能無法使用 2.non default parameter follows def...

python報錯集錦

解決 把os.mkdir 修改為 os.makedirs即可 1.mkdir path mode 作用 建立乙個目錄,可以是相對或者絕對路徑,mode的預設模式是0777。2.makedirs path mode 作用 建立遞迴的目錄樹,可以是相對或者絕對路徑,mode的預設模式也是0777。ope...

python報錯除錯

1.python獲取上級目錄的三種方式os.path.abspath os.path.join projpath,os.path.dirname os.getcwd os.path.split projpath 0 2.modulenotfounderror no module named 在pyc...