如何在 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