Configuration

Night mode

If Else

Learn Python Essentials for Data Science Course

Engineers From These Top Companies and Universities Trust EXLskills

1M+ Professionals | 100+ Institutions

This is the EXLskills free and open-source Python Introduction Course. It guides learners via explanation, demonstration, and thorough practice, from no more than a basic understanding of Python, to a moderate level of essential coding proficiency.

Is this course FREE?

Yes, this a 100% free course that you can contribute to on GitHub here!

Have more questions?

Learning Booleans

If Else

Python Logic Statements

Just like in life, you can use a computer to make basic if statements. This implies that if something meets a certain condition (based on what we learned with Operators) you can get the code to execute different code.

The code below will print out the value 3 since it meets the condition

# Declare the variable
x = 3
# Set up the condition
if x < 3:
print('x < 3')
# Set up the elif condition
elif x > 3:
print('x > 3')
# Set up the else condition
else:
print('x is not less than three and it is not greater than 3')