如何在 Python 中捕获 TypeError 异常?
pythonserver side programmingprogramming更新于 2025/6/20 14:36:17
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'>
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

