• Home
  • Python
  • About
  • Conditionals

    The most basic conditional structure is an if statement with a condition:

    color = "Blue"
    # use == for comparisons
    if color == "Blue":
        print("Perfect!")

    We can nest more conditions with elif (else if):

    if color == "Blue":
        print("Perfect!")
    elif color == "Red":
        print("It's ok")

    Optionally, we can add else to handle the rest:

    if color == "Blue":
        print("Perfect!")
    elif color == "Red":
        print("It's ok")
    else:
        print("Meh")
    Introduction
    Lists
    Github Back to the top