0

Whatâs the point of using order of precedence with bools? (True , false)

Iâve just started learning about it in my python course. I find it more useful for math based things like adding but whatâs the point of it in bools?? And, or, not etc

8th Nov 2019, 3:40 PM
Theodore206
+ 1
Its similar to maths. Maths has BODMAS and DMAS and for python its this.
8th Nov 2019, 4:16 PM
D Dheeraj
+ 2
The point of it is to keep evaluations of statements consistent, just like in maths. You know in maths that changing the order of operations can change the result you get from a calculation, so you need BODMAS to have a consistent system for calculating expressions and decide the right answer. The same happens with evaluating statements with Booleans. Consider the following: not True and False Not takes precedence over and, so we evaluate the not expression first and then the and: not True and False -> False and False -> False But if we swap the order so that and takes precedence over not, and evaluate and first, then we get a different answer: not True and False -> not False -> True So we need the order of operations for Booleans just like in maths to decide which is the right answer (the first).
9th Nov 2019, 8:41 PM
Njeri
0
and if math is not a huge part of my code?
8th Nov 2019, 5:24 PM
Theodore206
0
Some or the other time you will use not, true just like math at that time it comes to help
8th Nov 2019, 5:28 PM
D Dheeraj
0
For eg: you have not and 'and' in the same program
8th Nov 2019, 5:29 PM
D Dheeraj
0
You will encounter questions like 'what will be executed first?' again and again in your programmer life - there's no getaway from that. Don't be afraid - you will gradually get a better understanding of it, and your maths will also improve - because you WILL need it here and there if you continue programming.
8th Nov 2019, 6:09 PM
HonFu