Python – Boolean Operators and Conditions


Basic conditions in Python:

< (one less than the other)
> (one more than the other)
<= (one is less than or equal to the other)
>= (one is greater than or equal to the other)
!= (one is not equal to the other)
== (one is equal to the other)

Examples of using conditions:

print(5 > 4)
True #result

print(‘cat’==’dog’)
False #result

Logical operators in Python (by precedence):

not (not)
and
or (or)

An example of using logical operators:

t=True
f=False
print(not t)
False #result

t=True
f=False
print(t and f)
False #result

t=True
f=False
print(t or f)
True #result

a = 1
b = 6
c=False
d = ‘Cat’
e = ‘Kitten’
f = not((not(a <= b) and (d < e)) or c) and 5
print(f)
5 #result


This entry was posted in Python (en). Bookmark the permalink.

Leave a Reply

🇬🇧 Attention! Comments with URLs/email are not allowed.
🇷🇺 Комментарии со ссылками/email удаляются автоматически.