Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python logical operator AND
#3
According to the python Docs :-
In the context of Boolean operations, and also when expressions are used by control flow statements, the following values are interpreted as false: False, None, numeric zero of all types, and empty strings and containers (including strings, tuples, lists, dictionaries, sets and frozensets). All other values are interpreted as true. User-defined objects can customize their truth value by providing a __bool__() method.

The operator not yields True if its argument is false, False otherwise.

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.

The expression x or y first evaluates x; if x is true, its value is returned; otherwise, y is evaluated and the resulting value is returned.

Note that neither and nor or restrict the value and type they return to False and True, but rather return the last evaluated argument. This is sometimes useful, e.g., if s is a string that should be replaced by a default value if it is empty, the expression s or 'foo' yields the desired value. Because not has to create a new value, it returns a boolean value regardless of the type of its argument (for example, not 'foo' produces False rather than ''.)
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
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,228 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