encoding:utf-8
在Python中,所有的标识符都是一个标签
f = print
print('123456')
type(print)
print = 123
f(type(print))
def fun3( function ):
function('123456')
fun3(print)
从异常基类派生出一个自定义异常类
class NetConnectError(Exception):
def init(self , errorMsg=''):
NetConnectError.what= errorMsg
def fun(name):
if not isinstance(name,str):
raise TypeError('类型错误')
print('类型正确')
print(isinstance(123 , str))
try:
fun(123)
except Exception as err:
print('fun产生异常:' , err)
try:
print(a)
l1 = [1,2,3,4]
l1[4] = 0
except Exception as err: # 将IndexError异常对象保存到err中
print('产生异常:',err)
print('ssssss')
网友评论