An if statement is a statement that will execute only if something is true (or false).

Syntax-

if # condition:

block 1 runs if condition is true

block 2 runs regardless

  1. First, the condition is checked (should be true or false)
  2. If the condition is true, the code inside the if statement (block 1) runs. Otherwise, skip to step 3
  3. The code in block 2 runs

“and” and “or” can also be used to modulate the function of if statements.