D:\Python36\python.exe E:/PyCharm/pythonbase/day01/02_變量.py Traceback (most recent call last): File “E:/PyCharm/pythonbase/day01/02_變量.py”, line 12, in print (name+age+hobby) TypeError: must be str, not int 類型錯(cuò)誤:必須是字符串,不能是整數(shù)型 解決方法:將整數(shù)型前邊加上str,轉(zhuǎn)化為字符串類型
File “E:/PyCharm/pythonbase/day01/03_程序的輸入與輸出.py”, line 7 print(1,2,3,4,5,sep=’-’) ^ IndentationError: unexpected indent 縮進(jìn)錯(cuò)誤:意外縮進(jìn) 解決:將print頂格/或4個(gè)空格
print(‘我本來(lái)有5元,現(xiàn)在一共有’,money+5,‘元’) TypeError: must be str, not int 錯(cuò)誤類型:此處5是int型 解決方法:print(‘我本來(lái)有5元,現(xiàn)在一共有’,str(5)+money,‘元’)
注意: 1.print(‘我本來(lái)有5元,現(xiàn)在一共有’,str(5)+money,‘元’) 輸出:我本來(lái)有5元,現(xiàn)在一共有 5**(字符串拼接) 元
2.print(‘我本來(lái)有5元,現(xiàn)在一共有’,‘str(5)+money’,‘元’) 輸出:我本來(lái)有5元,現(xiàn)在一共有 str(5)+money(不會(huì)對(duì)內(nèi)容拼接,,直接顯示引號(hào)中的內(nèi)容) 元
print(‘我本來(lái)有5元,現(xiàn)在一共有’,5+money,‘元’) TypeError: unsupported operand type(s) for +: ‘int’ and ‘str’ 錯(cuò)誤類型:此處money是字符串 數(shù)字后面跟+,,默認(rèn)是做數(shù)學(xué)運(yùn)算
解決方法:print(‘我本來(lái)有5元,現(xiàn)在一共有’,5+int(money),‘元’)
print (students4) IndexError: list index out of range 錯(cuò)誤類型: 索引錯(cuò)誤:超出列表的索引范圍(下標(biāo)太大) 解決方法:更改下標(biāo) 或 增添索引的范圍即添加內(nèi)容
a[0]=‘H’ TypeError: ‘str’ object does not support item assignment 錯(cuò)誤類型:字符串對(duì)象不支持項(xiàng)目分配
b[0]=‘H’ TypeError: ‘tuple’ object does not support item assignment 錯(cuò)誤類型:元組對(duì)象不支持項(xiàng)目分配
TypeError: myprint() missing 1 required positional argument: ‘x’ 錯(cuò)誤類型:函數(shù)xmyprint缺失 運(yùn)行所需的函數(shù)x 的值 解決方法: 添加x 的函數(shù)
AttributeError: ‘person’ object has no attribute ‘score’ 屬性錯(cuò)誤:某個(gè)隊(duì)形(person)缺失某個(gè)屬性(score) 解決方法:添加屬性
TypeError: write() argument must be str, not int
ValueError: I/O operation on closed file. value錯(cuò)誤:I/O 操作在關(guān)閉的文件上 文件被代碼關(guān)閉,無(wú)法再寫入 解決方法:將代碼放置 file.close()函數(shù)之前
PermissionError: [Errno 13] Permission denied: ‘newExcel.xls’
|