0

What is the correct thinking about the syntax?

[] and {} or 1

Result of this code is 1 I am not sure how to explain this example.

I tried understanding [] and {} and this return []

Martin Inf1n1ty
  • 197
  • 1
  • 1
  • 7
  • See [this](https://stackoverflow.com/questions/39983695/what-is-truthy-and-falsy-how-is-it-different-from-true-and-false) and [this](https://stackoverflow.com/questions/22598547/why-do-and-or-return-operands-in-python). – ayhan Sep 03 '19 at 21:56
  • One should also point out [operator precedence](https://docs.python.org/3/reference/expressions.html#summary) and Python's left-to-right evaluation. – Daniel Lenz Sep 03 '19 at 22:03

1 Answers1

1

In order of operations, and comes before or, so the effective statement is

([] and {}) or 1

bool([]) is False.

bool({}) is False.

Therefore, [] and {} is [].

Finally, [] or 1 is 1.

chepner
  • 497,756
  • 71
  • 530
  • 681
Kirk Strauser
  • 30,189
  • 5
  • 49
  • 65