Python 003- 小知识汇总(更新中)时间:2023-03-09 06:56:09 #查询key是否存在,可以在使用未知的字典的时候使用 #-*- coding:utf-8 -*- D={'a':1,'c':3,'b':2} for key in sorted(D): print(key,'->',D[key]) if not D.has_key('f'): print('this key is not in dic') #lambda表达式,可以理解为一个未定义的函数 lambda_plus=lambda x:x+1 print(lambda_plus(1))