首页 > 解决方案 > 我想在 Python 的 if 语句中有多个值

问题描述

我不完全确定该怎么做。感谢您提供任何帮助,对于新手问题感到抱歉。

if input_num != 8 or 16 or 32 or 64 or 128 or 256:
    #some function

我认为问题是“或”,我认为这不是正确的方法。

标签: python

解决方案


您必须每次都重复该语句,如下所示:

if input_num != 8 and input_num != 16 and input_num != 32 and input_num != 64 and input_num != 128 and input_num != 256:

推荐阅读