boolean in python
#In programming you often need to know if an expression is True or False.
#as you can see below
a = 200
b = 33
if b > a:
print("b is greater than a")
else:
print("b is not greater than a")
4.33
3
The Python Boolean type is one of Python's built-in data types. It's used to represent the truth value of an expression. For example, the expression 1 <= 2 is True , while the expression 0 == 1 is False .
Thank you!
3
0
3.83
6
>>> # The not operator is the opposite of it
>>> not True
False
>>> not False
True
>>> # The and operator is True only if both are are true
>>> True and True
True
>>> False and True
False
>>> False and False
False
>>> # The or operator is True if either of them are true
>>> True or True
True
>>> False or True
True
>>> False or False
False
Thank you!
6
0
3.75
8
# Returns the boolean value of the specified object
x = bool(1) # outputs True
Thank you!
8
0
3.78
9
#The Python Boolean type is one of Python's built-in data types. It's used to represent the truth value of an expression.
#in this code if you're age is under 13 than a massage will tell you that you are not able to sign up
Name = input("Povide your name : ")
Email = input("Provide your email : ")
age = input("Provide your age : ")
if age < "13":
print("you are not able to sign up")
else:
if age > "13":
print("you are able to sign up")
Thank you!
9
0
4
4
>>> type(True)
<class 'bool'>
>>> type(true)
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
NameError: name 'true' is not defined
Thank you!
4
0
Are there any code examples left?
New code examples in category Python