Conditions

Python uses boolean variables to evaluate conditions. True and False are returned when an expression is compared or evaulated.

This is shown as such:

x = 2

print(x == 2)

* True*

print(x == 3)

* False*

print(x < 3)

* True*

print( x > 3)

* False*

Make sure you realise that variable assignment is done using a single equals "=" whereas comparison is done using double equals "==" and to compare if something is NOT equals to it is the "!=" operator

Boolean operators
There is "and" and "or" operators which allow more complex comparrisons to be carried out.

This means that you can create an if statement that requires certain conditions such as the name being "John" AND the age being 20. This is done by simplying typing "if name == "John" and age == 20:"

Or you can create an if statement that alllows a selection of conditions to be met, such as the name being "John" OR "Bob"

This is done by typing "if name == "John" or name == "Bob":

The "in" operator
The "in" operator simply checks if a specified object exists within the given container.

number = 4

if number in [ 1, 2, 3, 4, 5]:

print("Your number is in the list!")

Make sure when using if statements you use indentation where appropriate such as just below the specified conditions and results.

The "is" operator
The "is" operator matches the instances of two variables compared to the values of the variables like "==" does.

x = 12

y= 12

print(x == y)

* True*

print(x is y)

* False*

The "not" operator
Using "not" before a boolean expression inverts it:

x = 12

y = 12

Boolean = print(x is y)

print(not Boolean)

* True*

Continue to next lesson.