Brackets are used in Python logical formulas to group certain expressions and determine the order of evaluation. Follow these guidelines to add brackets to your logical formulas:
2 + 3 * 4
, you can use brackets to indicate that the multiplication should be done first: 2 + (3 * 4)
.a or b and c
, you can use brackets to indicate that b and c
should be evaluated first: a or (b and c)
.Some examples of where you might add brackets to a Python logical formula include:
(x > 5) and (y < 10)
not (a == b or c < d)
(a + b < 10) or (c - d == 0)
In general, the key is to think about the order of evaluation and use brackets to group expressions together in the way that makes the most sense.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-11-16 11:00:00 +0000
Seen: 24 times
Last updated: Jul 16 '22