python - if True 和 if False 语句

标签 python python-2.7

我一直对在 if 语句中使用 True 和 False 感到困惑。例如,假设我定义了一个返回 True 或 False 的函数。

def isEven(number):
    if number % 2 == 0:
        return True
    else:
        return False

现在我需要在我的其中一个代码上使用该函数,该函数只有在数字为偶数时才能继续。我相信我已经看到像 if isEven(number): proceed etc etc 这样的代码,我的问题是,默认情况下它是否被认为是 True?或者我应该继续使用 if isEven(number) == True

最佳答案

当你有类似的事情时:

if myboolean : ...

意思是“如果 myboolean 为真,则执行后面的操作”。所以它与 :

if myboolean==true : ...

关于python - if True 和 if False 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20037361/

相关文章:

python - TTK 主题不起作用,只是老式的 tkinter

android - 从现有实例调用方法

python - 为什么即使我使用了 str(),仍然打印 'u' 前缀?

python - 在没有 insert() 或 append() Python 的情况下将项目插入列表

python - 使用 Python 2 的套接字接口(interface)分别发送多个字符串

python - 使用 os.rename 重命名文件导致 NameError

python-2.7 - 如何为wit.ai中的 'wit$location'等内置实体添加值

java - 用于故障排除的指标模式分析

python - iloc 给 'IndexError: single positional indexer is out-of-bounds'

python - pandas 没有将类型 string 转换为 float