问:如何在python列表理解中使用OR?
numbers = [x for x in range(99) if x % 5 == 0 if x % 7 == 0]
这些数字可以被5和7整除。我也试过:
numbers = [x % 5 == 0 or x % 7 == 0 for x in range(99)]
numbers = [x for x in range(99) if x % 5 == 0 or if x % 7 == 0]
我已经看了下面的几页,但不知道如何应用这些解决方案,如果他们提出了。它们似乎都为我想要的解决方案提供了细微差别,但并不是我想要的。
datacamp.com/community/tutorials/python-list-comprehension
programiz.com/python-programming/list-comprehension
use-of-or-operator-in-python-lambda-function
not-comprehending-list-comprehension-in-python
is-there-a-binary-or-operator-in-python-that-works-on-arrays
how-to-convert-this-my-code-into-a-list-comprehension
python-list-comprehension-with-multiple-ifs
if !
if
numbers = [x for x in range(99) if (x % 5 == 0) or (x % 7 == 0)] print(numbers)
如果 or 如果
如果
or