Python: Boolean
What's the use of the extra "True"s and "False" in this code? my_boolean = True print(my_boolean) True print(2==3) False print("hello" == "hello") True
4/28/2021 11:50:42 AM
Koloroj
15 Answers
New AnswerThe True and False that get printed are the values of what's inside print(): x = (2 == 3) print(x) # False print(2 == 3) # False
🅰🅹 🅐🅝🅐🅝🅣 The "False" after "print(2==3)" and the "True" after "print("hello" == "hello")". The code displays the respective words at those lines even without the "True" and the "False".
print(x) is the code that is executed in console. False, for example is the value that is printed in console in you console it may look like this >>> False
🅰🅹 🅐🅝🅐🅝🅣 I have a feelong you thought that the "True"s and the "False" are just indicators or the outputs. Just in case you think so, no, that's the entire exact code, the Boolean values included. My problem is why they are there when the "print" commands already display the values "True" and "False" perfectly fine all by themselves.
Writing True anywhere in the script without assigning it or something like that doesn't do much? Maybe they were intended as comments???
Okay, maybe it was meant as comment or example... https://code.sololearn.com/cRkFl30uiN64/?ref=app
🅰🅹 🅐🅝🅐🅝🅣 Precisely! I don't know why they're there after the print statements when the print statements already display the values by themselves perfectly fine.
Booleans represent one of two values: True or False. 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: Example- print(10 > 9) # True print(10 == 9) # False print(10 < 9) # False When you run a condition in an if statement, Python returns True or False: Example Print a message based on whether the condition is True or False: a = 200 b = 33 if b > a: # False : the if statement doesn't run print("b is greater than a") else: print("b is not greater than a") The output of the above code: b is not greater than a I hope you understand it 😊