Python Forum
Mixing Boolean and comparison operators
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mixing Boolean and comparison operators
#1
I'm reading an intro to Python book and it gives these examples:

>>> (4 < 5) and (5 < 6)
True
>>> (4 < 5) and (9 < 6)
False
>>> (1 == 2) or (2 == 2)
True
Then it says:

> The computer will evaluate the left expression first, and then it will evaluate the
> right expression. When it knows the Boolean value for each, it will then evaluate
> the whole expression down to one Boolean value.

This feels intuitively right to me. However, I thought a while back I asked about some weird results I was getting with this sort of thing involving and/or and the reason it didn't turn out as I expected was because once one part was deemed to be False, it did not process the remainder of the expression. I can't remember if that was dealing with and or or.

Does anyone know what I might be misremembering or confused about here? Thanks!
Reply


Messages In This Thread
Mixing Boolean and comparison operators - by Mark17 - Jul-10-2022, 02:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Use of if - and operators Pedro_Castillo 1 579 Oct-24-2023, 08:33 AM
Last Post: deanhystad
  Magic Method Arithmetic Operators ClownPrinceOfCrime 3 2,425 Jan-10-2021, 03:24 PM
Last Post: ndc85430
  Class and Operators in Python rsherry8 1 2,053 May-27-2020, 07:09 PM
Last Post: buran
  Trying Comparison Operators PythonGainz 3 2,812 Mar-28-2020, 10:46 AM
Last Post: PythonGainz
  Mathematical Operators in String AgileAVS 1 2,472 Mar-04-2020, 04:14 PM
Last Post: Gribouillis
  A doubt with 'in' and 'not in' operators with strings newbieAuggie2019 7 3,753 Oct-23-2019, 03:11 PM
Last Post: perfringo
  understanding exponential and bitwise operators srm 1 2,159 Jun-15-2019, 11:14 AM
Last Post: ThomasL
  please help with this question about using operators to multiply a string? GilesTwigg 3 4,525 Feb-27-2019, 04:13 PM
Last Post: ichabod801
  Understanding compound operators -= NewatCode 3 3,285 Apr-25-2018, 05:03 PM
Last Post: Larz60+
  Pycharm shortcuts and operators don't run AzD 6 8,152 Oct-17-2017, 05:46 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020