About 3,690,000 results
Open links in new tab
  1. python - Syntax for an If statement using a boolean - Stack Overflow

    Boolean logic in Python statement. 0. Python3 boolean if statement. 0. python if evaluating True for False ...

  2. How do I use a Boolean in Python? - Stack Overflow

    Mar 16, 2018 · But also Python has the boolean-able concept for every object, which is used when function bool([x]) is called. See more: object. nonzero and boolean-value-of-objects-in …

  3. What is Python's equivalent of && (logical-and) in an if-statement?

    Mar 21, 2010 · Note that this is pseudo-code not Python code. In Python you cannot create functions called and or or because these are keywords. Also you should never use "evaluate" …

  4. How to use boolean 'and' in Python - Stack Overflow

    Dec 8, 2013 · Since we're dealing with booleans (i == 5 is True and ii == 10 is also True), you may wonder why this didn't either work anyway (True being treated as an integer quantity should …

  5. How to apply a logical operator to all elements in a python list

    Nov 24, 2009 · The idiom for such operations is to use the reduce function (global in Python 2.X, in module functools in Python 3.X) with an appropriate binary operator either taken from the …

  6. Converting from a string to boolean in Python - Stack Overflow

    Since Python 2.6 you can use ast.literal_eval, and it's still available in Python 3.. Evaluate an expression node or a string containing only a Python literal or container display.

  7. How do I get the opposite (negation) of a Boolean in Python?

    But because bool is a subclass of int the result could be unexpected because it doesn't return the "inverse boolean", it returns the "inverse integer": >>> ~True -2 >>> ~False -1 That's because …

  8. Beginner question: returning a boolean value from a function in …

    Nov 12, 2010 · I'm trying to get this rock paper scissors game to either return a Boolean value, as in set player_wins to True or False, depending on if the player wins, or to refactor this code …

  9. Get a random boolean in python? - Stack Overflow

    Jul 26, 2011 · $ python -m timeit -s "from random import getrandbits" "not getrandbits(1)" 10000000 loops, best of 3: 0.222 usec per loop $ python -m timeit -s "from random import …

  10. How do you get the logical xor of two variables in Python?

    Apr 30, 2017 · As Zach explained, you can use:. xor = bool(a) ^ bool(b) Personally, I favor a slightly different dialect: xor = bool(a) + bool(b) == 1

Refresh