如何在 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'>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP