+ 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

28th Apr 2021, 11:50 AM
Koloroj
16 Respostas
+ 3
Koloroj Where is extra True and False? True or False returns on the basis of comparison
28th Apr 2021, 11:56 AM
A͢J
A͢J - avatar
+ 2
Koloroj Those are not comments. Those are values returned after comparing two values.
28th Apr 2021, 1:43 PM
A͢J
A͢J - avatar
+ 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
28th Apr 2021, 1:21 PM
Lisa
Lisa - avatar
+ 1
Lisa Maybe. This is from the Python lesson on Booleans, by the way.
28th Apr 2021, 1:53 PM
Koloroj
+ 1
🅰🅹 🅐🅝🅐🅝🅣 and Lisa Well, thanks for helping me confirm.
28th Apr 2021, 1:56 PM
Koloroj
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".
28th Apr 2021, 12:31 PM
Koloroj
0
Lisa So those are just comments? But why don't they have the hashtags, then?
28th Apr 2021, 1:37 PM
Koloroj
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
28th Apr 2021, 1:40 PM
Lisa
Lisa - avatar
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.
28th Apr 2021, 1:46 PM
Koloroj
0
Writing True anywhere in the script without assigning it or something like that doesn't do much? Maybe they were intended as comments???
28th Apr 2021, 1:49 PM
Lisa
Lisa - avatar
0
Koloroj Are you talking about lesson? Why there those values are given after print statement?
28th Apr 2021, 1:52 PM
A͢J
A͢J - avatar
0
Okay, maybe it was meant as comment or example... https://code.sololearn.com/cRkFl30uiN64/?ref=app
28th Apr 2021, 1:54 PM
Lisa
Lisa - avatar
0
Koloroj That's just for Explanation to understand concepts nothing else.
28th Apr 2021, 1:54 PM
A͢J
A͢J - avatar
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.
28th Apr 2021, 1:54 PM
Koloroj
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 😊
29th Apr 2021, 1:09 AM
Sagar Yadav
Sagar Yadav - avatar
0
Hey fill in the blankspace Open=false _(_)
9th Sep 2022, 6:04 AM
DRAJIRU SHARON
DRAJIRU SHARON - avatar