【问题标题】:Putting multiple "If not" together [duplicate]将多个“如果不是”放在一起[重复]
【发布时间】:2020-11-01 22:29:36
【问题描述】:

我想知道我是否可以这样做,这是为 Reddit 机器人准备的

submission = next(x for x in memes_submissions if not x.over_18 if not x.stickied)

【问题讨论】:

  • 你有什么问题?
  • 我可以这样做吗?将多个if not 放在一起
  • 你试过了吗?

标签: python python-3.x


【解决方案1】:

使用andor 组合条件。

submission = next(x for x in memes_submissions if not x.over_18 and not x.stickied)

【讨论】:

  • 它们可能意味着理解末尾的多个ifs 的含义。我不知道,但显然你可以列出多个 ifs,它们被视为 and'd。
猜你喜欢
  • 1970-01-01
  • 2015-03-04
  • 2021-05-15
  • 2011-06-18
  • 1970-01-01
相关资源
最近更新 更多