+ 2
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
16 Respostas
+ 3
Koloroj
Where is extra True and False?
True or False returns on the basis of comparison
+ 2
Koloroj
Those are not comments. Those are values returned after comparing two values.
+ 1
The True and False that get printed are the values of what's inside print():
x = (2 == 3)
print(x)
# False
print(2 == 3)
# False
0
🅰🅹 🅐🅝🅐🅝🅣
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".
0
Lisa
So those are just comments? But why don't they have the hashtags, then?
0
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
0
🅰🅹 🅐🅝🅐🅝🅣
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.
0
Writing True anywhere in the script without assigning it or something like that doesn't do much? Maybe they were intended as comments???
0
Koloroj
Are you talking about lesson? Why there those values are given after print statement?
0
Okay, maybe it was meant as comment or example...
https://code.sololearn.com/cRkFl30uiN64/?ref=app
0
Koloroj
That's just for Explanation to understand concepts nothing else.
0
🅰🅹 🅐🅝🅐🅝🅣
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.
0
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 😊
0
Hey fill in the blankspace
Open=false
_(_)