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