Python Forum
Help with or operator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with or operator
#5
See my example in the previous post.
Every non-empty string is True.
>>> bool('Tom')
True
>>> bool('Victor')
True
So False or True is True. True or True is also True.

Whatever the name is, the if statement will be True.

myName == 'Tom' or 'Jerry' can be translate to (myName == 'Tom') or 'Jerry'. So it becomes False or True which is True or True or True which is also True.

Here is the example:
>>> myName = 'Vanessa'
>>> bool(myName == 'Tom' or 'Jerry')
True
Obviously myName is not Tom or Jerry but still this condition evaluates to True. Because 'Jerry' evaluates to True and the or operator.

Here you can see how all the logical operators work:
>>> True and False
False

>>> True and True
True

>>> False and True
False

>>> False or True
True

>>> False or False
False
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
Help with or operator - by Hamut - May-31-2018, 05:46 PM
RE: Help with or operator - by buran - May-31-2018, 06:03 PM
RE: Help with or operator - by wavic - May-31-2018, 06:04 PM
RE: Help with or operator - by Hamut - May-31-2018, 06:41 PM
RE: Help with or operator - by wavic - May-31-2018, 07:11 PM

Forum Jump:

User Panel Messages

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