If Statements

If Statements

Conditionals: Features of programming language that allows different computations to occur based on decision making.

  • Conditionals are dependent on Boolean expressions that are evaluated to True or False.

  • Different texts will define conditionals to be statements, expressions, or constructs.

  • The use of conditionals is the way to control the flow of a program.

if statement

  • if is a built-in keyword in Python that allows us to write conditional statements.

  • if statements will only execute their own block of code if its boolean condition evaluates to True.

  • if the boolean condition doesn’t evaluate to True, the program will skip its block of code

  • Block of code or Code Block in python are started by a (:) colon and indentation. (Examine the example below)

# if statement formatting template

if (boolean_expression_here): # notice the colon to start the if's code block
    # single indentation

    code written here
# end of the if statement

code written here ... outside of the if statement

Last updated