python 中del ,pop ,popitem ,remove 比较图
cmd | args | list | dict |
del | has | del l[index] ; del l[start:end] | del dict[key] |
hasn't | del all | del all | |
pop | has | list.pop(index) | dict.pop(key) #随机的 |
hasn't | del all | NO | |
popitem | has | NO | dict.popitem(key) |
hasn't | NO | NO | |
remove | has | list.remove(ele) | NO |
hasn't | NO | NO |
装饰器:
def f(): print('function name : ', f.__name__ , ' ') print(f) # f 函数名指在内存中的位置,f():执行函数,或者函数调用 f() ############################################################################## def outer(func): def inner(*args , **kwargs): print('before ....... ') res = func(*args, **kwargs) print('after ....... ') return res return inner @outer def f2(): print('function name : ', f2.__name__) @outer def f3(l , d): print('list : {0}'.format(l)) print('dict : {0}'.format(d)) f2() f3(['a' , 'b' ] ,{'c':111})
Result :
<function f at 0x7f1a8d03ee18> function name : f before ....... function name : inner after ....... before ....... list : ['a', 'b'] dict : {'c': 111} after .......
EG3:
logging