Learn Before
Code

Examples of Logical Expressions

and:

x = 5 if x < 10 and x > 2: print(x, " is less than 10 and greater than 2.")

result:

5 is less than 10 and greater than 2.

or:

x = 5 if x < 10 or x > 7: print(x, " is less than 10 or greater than 7.")

result:

5 is less than 10 or greater than 7.

not:

x = 5 if not(x == 10): print(x, "doesn't equal 10.")

result:

5 doesn't equal 10.

0

1

Updated 2021-08-25

Tags

Python Programming Language

Data Science