Follow

Follow

# Day 5 of #30-day-of-coding

## Conditions in python

Eliud Githuku
·Dec 11, 2022·

if statements if statements in python checks whether a certain condition is met then something will be done, for instance, if 6 is divisible by 2, then it is an even number. Syntax example of the if statement:

``````a = 6
b = 4
if a > b:
print('a is greater than b')
``````

else statement Else statement is used to run anything that is not met by the if statement. When the if statement is left without an else statement, then nothing happens when the conditions are not met. Syntax of the else statement:

``````a = 6
b = 8
if a > b:
print('a is greater than b')
else:
print('a is not greater than b')
``````

elif statement the elif statement is used to continue testing the conditions. The syntax of the elif statement is as follows:

``````a = 6
b = 8
if a > b:
print('a is greater than b')
elif a == b:
print('a is equal to b')
elif a >= b:
print('a is greater or equal to b')
else:
print('a is not greater than b')
``````

the OR condition The OR condition means that even if only one of the stated conditions is met, then the statement is run. The condition only checks if one condition in the statement is met. Example of syntax for the or condition:

``````a = 9
b = 7
if a > b or a == b:
print('one of the condition is met')
``````

The AND condition The and condition, unlike the or condition, checks and verifies that both statements are met for the statement to run. If one of the statements is not met, then the statement does not run. The and condition is really critical when confirming login credentials are correct. The syntax for the and condition is:

``````a = 9
b = 9
c = 7
if a > c and a == b:
print('All the conditions have been met')
``````

The if statement, elif, else, or, and the and statements are the common conditions that are found in python. There are other conditions such as >, which means greater than, <, which means less than, ==, which means equal to, and the !=, which means not equals to. These are some of the common condition statements in python.