Create a Simple If Statement With Python

This post will show how to create a very simple if statement using Python and compare values.

If Statement

The whole idea behind an if statement is to compare values and build a logic that action tasks based on the results of the statement. Creating an if statement with Python is not complicated as you will see in the following code.

Code

Let’s have a look at the following code. We have two values and an if statement that compare them. If the result is true something will print.

value1 = 10
value2 = 10 
if value1 == value2:
    print("Value1 is the same as value2 ")

Python Comparison Operators

The following table shows the comparison operators that are available in Python.

Operators Details
==Equal
!=Not equal
>=Greater or equal to
<=Less or equal to
>Greater than
<Less than
Python comparison operator

Leave a comment

Your email address will not be published. Required fields are marked *