About 3,400,000 results
Open links in new tab
  1. How do I use a Boolean in Python? - Stack Overflow

    Mar 16, 2018 · Does Python actually contain a Boolean value? I know that you can do: checker = 1 if checker: #dostuff But I'm quite pedantic and enjoy seeing booleans in Java. For instance: …

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

    Mar 21, 2010 · There is no bitwise negation in Python (just the bitwise inverse operator ~ - but that is not equivalent to not). See also 6.6. Unary arithmetic and bitwise/binary operations and …

  3. Syntax for an If statement using a boolean - Stack Overflow

    I just recently joined the python3 HypeTrain. However I just wondered how you can use an if statement onto a boolean. Example: RandomBool = True # and now how can I check this in …

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

    The string or node provided may only consist of the following Python literal structures: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, None and Ellipsis. This can be used for …

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

    To negate a boolean, you can use the not operator: not bool Or in your case, the if / return blocks can be replaced by: return not bool Be sure to note the operator precedence rules, and the …

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

    Dec 8, 2013 · As pointed out, "&" in python performs a bitwise and operation, just as it does in C#. and is the appropriate equivalent to the && operator.

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

    Apr 30, 2017 · Still, Python has built-in the ^ operator for many bits in int and for the one bit represented in a bool, so both are bitwise, but the bitwise xor for a single bit just is the logical …

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

    Nov 24, 2009 · I have a list of booleans in python. I want to AND (or OR or NOT) them and get the result. The following code works but is not very pythonic. def apply_and (alist): if len (alist) > 1: …

  9. python - Parsing boolean values with argparse - Stack Overflow

    Here is another variation without extra row/s to set default values. The boolean value is always assigned, so that it can be used in logical statements without checking beforehand: import …

  10. python - Logical operators for Boolean indexing in Pandas - Stack …

    Python's and, or and not logical operators are designed to work with scalars. So Pandas had to do one better and override the bitwise operators to achieve a vectorized (element-wise) version of …