About 21,900,000 results
Open links in new tab
  1. How to set python variables to true or false? - Stack Overflow

    I want to set a variable in Python to true or false. But the words true and false are interpreted as undefined variables: #!/usr/bin/python a = true; b = true; if a == b: print("same");

  2. Python Booleans - W3Schools

    In programming you often need to know if an expression is True or False. You can evaluate any expression in Python, and get one of two answers, True or False. When you compare two values, the expression is evaluated and Python returns the Boolean answer:

  3. Python True Keyword - GeeksforGeeks

    Mar 6, 2025 · True is a built-in Boolean value that represents truth or logical true value. It is one of the two Boolean constants (True and False) and is often used in conditions, loops and logical operations. Python treats True as 1 when used in arithmetic operations and as a truthy value in conditional statements (if-else). Let's take an example. Python

  4. boolean - 'True' and 'False' in Python - Stack Overflow

    Python does not treat anything with a value as True. Witness: print("Won't get here") This will print nothing because 0 is treated as False. In fact, zero of any numeric type evaluates to False. They also made decimal work the way you'd expect: print("Won't get here") Here are the other value which evaluate to False: print("Won't get here")

  5. Python Boolean - GeeksforGeeks

    Dec 5, 2024 · In Python, the bool () function is used to convert a value or expression to its corresponding Boolean value (True or False). In the example below the variable res will store the boolean value of False after the equality comparison takes place. Note: It’s not always necessary to use bool () directly.

  6. Boolean Variables in Python - Learn How to Declare and Use Bool …

    May 3, 2024 · To declare a Boolean variable in Python, you simply assign the value True or False to a variable name. Here's an example: x = True y = False You can also use Boolean operators such as and, or, and not to combine or negate Boolean values. For example: a = True b = False print(a and b) # False print(a or b) # True print(not a) # False

  7. Python Booleans: Use Truth Values in Your Code – Real Python

    For example, the expression 1 <= 2 is True, while the expression 0 == 1 is False. Understanding how Python Boolean values behave is important to programming well in Python. In this tutorial, you’ll learn how to: Manipulate Boolean values with Boolean operators; Convert Booleans to other types; Convert other types to Python Booleans

  8. Python True Keyword - W3Schools

    The True keyword is a Boolean value, and result of a comparison operation. The True keyword is the same as 1 (False is the same as 0).

  9. True | Python Keywords – Real Python

    In Python, the True keyword represents a Boolean value indicating a truth value in logical operations and expressions. It’s defined as a built-in constant with a value of 1 and is a subclass of int. Here’s an example demonstrating how the True keyword can be used in Python:

  10. Booleans, True or False in Python - Python

    In Python, the boolean data type is capitalized: True and False. Unlike some other languages, you don’t need to declare a variable as boolean explicitly in Python. The interpreter determines its type based on the assigned value. Here’s a simple comparison of …

  11. Some results have been removed
Refresh