2024-03-28 09:56:51 发布
网友
我想知道只有在关键字参数被调用时才对其执行操作的最佳方式(最具pythonic和/或优雅)是什么。比如:
import keyword def (*arg, **kwargs): if keyword.iskeyword(parameter): # Do stuff involving parameter # Do other stuff return 0
检查所需的键是否在kwargs参数中:
kwargs
def foo(*arg, **kwargs): if 'bar' in kwargs: print('You called foo with bar={}'.format(kwargs['bar'])) else: print('You didn't use the "bar" keyword argument')
检查所需的键是否在
kwargs
参数中:相关问题 更多 >
编程相关推荐