OneBite.Dev - Coding blog in a bite size

use if conditional statement in python

Code snippet on how to use if conditional statement in python

x = 200
if x == 200:
   print("x equals 200, yay!")

This code snippet checks the value of the variable “x”, and if it is equal to 200, a message will print out.

The first line, “x = 200”, assigns a value of 200 to the variable “x”. The following line is an “if” statement, which is a conditional statement. This statement evaluates to true or false, and if it is true, the statement inside the code block (enclosed in the colon : and indentation) will be executed. In this case, the statement checks whether the value of x is 200. If it is, the message “x equals 200, yay!” will be printed out.

python