1. 程式人生 > >Python基礎學習篇-7 各種常見報錯及原因----【不定時補充】

Python基礎學習篇-7 各種常見報錯及原因----【不定時補充】

1、TypeError: int(x) argument must be a string, a bytes-like object or a number, not 'NoneType'

此報錯是因為使用 int() 函式進行強制型別轉換時,要求引數x必須是字串、位元組物件、數字,不能是其它的型別(這裡是因為函式中的引數x獲取到的值是None,所以應該進一步去檢查x的取值邏輯)。

實際中還會遇到類似的錯誤,如:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'

原因都是類似的,要檢查int()函式中的引數值。
 

2、TypeError: 'int' object is not subscriptable

此報錯一般是在整數上加了下標。