Home Dictionary Game About

If, Else and Elif Statements

Python uses the basic mathematical logic constructors, such as:


You can use these logic pieces inside of If, Else or Elif Statements


If Statement


The usage of if checks if the conditions have been fufilled, if so, it executes the code inside of the function.


Example

- Use an if statement

a = 50

b = 100

if a < b:

print("A is less than B!")


Else Statement


Else is used when a prior condition hasnt been filled, so it reroutes to the code inside the else function.


Example

- Use an else statement

a = 50

b = 100

if a < b:

print("A is less than B!")

else:

print("A is More than B!")

Elif Statement


Elif is written onto the end of an if statement, saying if the first condition hasn't been filled, check this second statement as well.


Example

- Use an elif statement

a = 50

b = 100

if a < b:

print("A is less than B!")

elif a == b:

print("A is equal to B!")

else:

print("A is More than B!")