About 32,900,000 results
Open links in new tab
  1. How to have user true/false input in python? - Stack Overflow

    user_answer = input("Is johnny hungry ").lower().strip() if user_answer == "true": # do something elif user_answer == "false": # do something else else: print("Error: Answer must be True or False")

  2. User input boolean in python - Stack Overflow

    Feb 15, 2018 · In Python, if you convert a string to a bool, for example: bool("False") the boolean value will be True, this is because if you convert a non-empty string to a bool it will always convert to True, but if you try to convert an empty string to a bool you'll get False.

  3. Python Booleans - W3Schools

    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: Example

  4. python - how to make a value true or false with an input

    When checking in if condition, instead of. You should have, One more solution: print("a switched to positive") a = True. print("a switched to negative") a = False. This will allow user to type "positive" or "negative" both in lower and caps. Also just "pos" and "neg" will be okay.

  5. Taking user input boolean (True/False) values in Python

    Apr 9, 2024 · To take user input boolean values: Use the input() function to take input from the user. Check if the provided value is equal to the strings True or False. Perform an action if either condition is met. user_input = input('Subscribe to newsletter?

  6. Yes/No question with user input in Python - bobbyhadz

    Apr 9, 2024 · To create a yes/no while loop with user input: Use a while loop to iterate until a condition is met. Use the input() function to get input from the user. If the user types no, use the break statement to break out of the loop.

  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 Conditional Statements and Loops

    These constructs allow you to make decisions and repeat operations, forming the backbone of algorithmic thinking in Python. Conditional Statements in Python. Conditional statements allow your program to make decisions based on certain conditions, executing different blocks of code depending on whether these conditions evaluate to True or False.

  9. Check for True or False in Python - GeeksforGeeks

    Nov 18, 2024 · We can use Comparison operator to check if an expression evaluates to True or False. == and != Operator can be used with if condition or while statement to evaluate an expression. Logical Operators (and, or, not) allow combining multiple conditions.

  10. Booleans, True or False in Python - PythonForBeginners.com

    Aug 28, 2020 · Boolean values are the two constant objects False and True. They are used to represent truth values (other values can also be considered false or true). In numeric contexts (for example, when used as the argument to an arithmetic operator), they behave like the integers 0 and 1, respectively.

  11. Some results have been removed
Refresh