How to Use Conditions in Python IF Logic

Srinimf
2 min readMar 15, 2023

The condition is a variable you can use in the IF logic whether to continue the logic or to skip the logic in python. Here’s the best example for your reference.

Condition in python if logic

Python logic that uses condition statement

# Python logic shows how to use condition statement
password = "admIn"
condition = (password == "admin")
# if condition is equal to True, which means the password is correct
if condition:
print("password correct")
#if condition is equal to False, which means the password is not correct.
if condition == False:
print("password incorrect")

The output is as below.

The password that has given in the condition statement is ‘admin’. So the result is False. In this case, the result is False because Python is case-sensitive, so admIn is not the same as admin.

That means the first if statement evaluates to False, so its print statement is skipped, and program control flows to the next if statement. Hence it has produced the output below:

password incorrect
** Process exited - Return Code: 0 **
Press Enter to exit terminal

From the above scenario, it tells how a password validations deal in Python.

The bottom-line

The example demonstrates how to check conditions in the IF logic in Python.

References

--

--