Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python logical operator AND
#2
from the docs:
Quote:The expression x and y first evaluates x; if x is false, its value is returned; otherwise, y is evaluated and the resulting value is returned.

also here:
Quote:Boolean Operations — and, or, not

These are the Boolean operations, ordered by ascending priority:
  • x or y: if x is false, then y, else x (1)
  • x and y: if x is false, then x, else y (2)
  • not x: if x is false, then True, else False (3)

Notes:
  1. This is a short-circuit operator, so it only evaluates the second argument if the first one is false.
  2. This is a short-circuit operator, so it only evaluates the second argument if the first one is true.
  3. not has a lower priority than non-Boolean operators, so not a == b is interpreted as not (a == b), and a == not b is a syntax error.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Python logical operator AND - by rasec70 - May-07-2020, 08:51 AM
RE: Python logical operator AND - by buran - May-07-2020, 08:58 AM
RE: Python logical operator AND - by pyzyx3qwerty - May-07-2020, 09:21 AM
RE: Python logical operator AND - by TomToad - May-07-2020, 01:52 PM
RE: Python logical operator AND - by pyzyx3qwerty - May-07-2020, 03:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with Logical error processing List of strings dmc8300 3 1,229 Nov-27-2022, 04:10 PM
Last Post: Larz60+
  Greedy algorithms on logical problems Opensourcehacker 0 1,631 Nov-22-2020, 05:12 PM
Last Post: Opensourcehacker
  Python greater than equal to comparison operator Ilangos 4 2,593 Sep-26-2020, 03:53 AM
Last Post: buran
  Unable to bit shift and logical OR bytes and ints? MysticLord 7 7,451 Sep-01-2020, 03:31 PM
Last Post: deanhystad
  Basic logical errors cpopescu 3 2,227 Jun-03-2020, 11:30 AM
Last Post: menator01
  Use of & operator, groupby in python abhi1693r 0 1,667 Mar-11-2020, 02:25 PM
Last Post: abhi1693r
  Comparison Operator "is" idle vs python command spisatus 3 2,931 Oct-29-2019, 10:00 PM
Last Post: DeaD_EyE
  parsing logical expression with pyparsing palo173 2 5,691 May-13-2019, 09:22 AM
Last Post: palo173
  Is there any <> operator in python 3.6 rajeev1729 1 3,224 Sep-11-2017, 07:46 AM
Last Post: Mekire

Forum Jump:

User Panel Messages

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