是否有在 1 个 if 语句中包含两个海象运算符的正确方法?
if (three:= i%3==0) and (five:= i%5 ==0):
arr.append("FizzBuzz")
elif three:
arr.append("Fizz")
elif five:
arr.append("Buzz")
else:
arr.append(str(i-1))
Run Code Online (Sandbox Code Playgroud)
该示例适用于three
但five
将“未定义”。