8
python中有内置的标识函数吗?
我想指出一个什么都不做的函数: def identity(*args) return args 我的用例是这样的 try: gettext.find(...) ... _ = gettext.gettext else: _ = identity 当然,我可以使用identity上面定义的方法,但是内置方法肯定会运行得更快(并避免我自己引入的错误)。 显然,map与filter使用None的身份,但这是具体到它们的实现。 >>> _=None >>> _("hello") Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'NoneType' object is not callable