如何在 Python 中捕捉 TypeError 異常?
TypeError 的成因是由於對錯誤型別的物件進行組合,或呼叫了具有錯誤型別的物件的函式。
示例
import sys try : ny = 'Statue of Liberty' my_list = [3, 4, 5, 8, 9] print my_list + ny except TypeError as e: print e print sys.exc_type
輸出
can only concatenate list (not ""str") to list <type 'exceptions.TypeError'>
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP