Search code examples
pythonif-statementchained

Are if-if and if-elif defined as chained conditionals?


I know the difference between if-if vs if-elif statements, but do both belong to the definition of a chained conditional, or is the definition of chained conditionals only with if-elif statements correct?


Solution

  • Yes, you are right. This is a chained conditional statement.

    if 1 > 2:
        print("1 > 2")
    elif 2 == 1:
        print ("2 == 1")
    else:
        print("2 > 1")
    

    And this is a sequence of conditional statements that are not chained together.

    if 2 > 1:
        print("2 > 1")
    if 3 > 2:
        print("3 > 2")