始终返回相同布尔值的Python函数 [英] Python function that always return the same boolean value

查看:97
本文介绍了始终返回相同布尔值的Python函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在函数式编程中,有时对于某些参数(甚至多个参数)总是返回True(或False)的函数有用.

In functional programming is sometimes useful to have a function that always return True (or False) for every parameter (or even multiple parameters).

某些模块中是否定义了具有这种确切行为的内置函数?

Is there a built-in or a function defined in some module that have this exact behaviour?

推荐答案

我不知道任何内置函数,但是您可以将它们定义为:

I'm not aware of any built-in, but you can define them as:

false = lambda *_: False
true  = lambda *_: True

这篇关于始终返回相同布尔值的Python函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆