Questions about Python operation order

Asked 2 years ago, Updated 2 years ago, 96 views

9%3==0 & 9%5==0

Expected result value: False, Actual result value: True

I know that this result comes out because of the difference in the order of calculation I wonder how the expression that comes out after calculating & comes out true.

9%3==(0 & 9%5)==0 Even if I tie it like this, it doesn't come out true...

python3.7

2022-09-22 11:09

1 Answers

I just looked it up and found that & and and are different in Python.

and is an operator that determines whether both sides are logically True and is an operator that determines whether both sides are True and (when used with the True value). Source

Therefore:

print(9 % 3 == 0  &  9 % 5 == 0) # True
print(9 % 3 == 0 and 9 % 5 == 0) # False

Python... You can't let your guard down...


2022-09-22 11:09

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.