Match And If-Else Interview Questions

    Question 1Python If-Else Condition

    What will be the output of this code?

    x = 10 if x > 5: print("Big") else: print("Small")

    Question 2Python If-Elif-Else Ladder

    What is the output?

    x = 0 if x > 0: print("Positive") elif x == 0: print("Zero") else: print("Negative")

    Question 3Python Nested If

    What will be printed?

    x = 15 if x > 10: if x < 20: print("Between 10 and 20")

    Question 4Python If with Boolean Expression

    What will this code print?

    x = 5 if x and 10: print("Yes") else: print("No")

    Question 5Python Match Statement

    Which keyword is used in Python to implement pattern matching (similar to switch-case)?

    Question 6Python Match with Cases

    What will this code output?

    x = 2 match x: case 1: print("One") case 2: print("Two") case _: print("Other")

    Question 7Python Match Default Case

    What symbol is used for the default case in Python match statements?

    Question 8Python Match Multiple Patterns

    What will this code print?

    x = 3 match x: case 1 | 3 | 5: print("Odd") case 2 | 4: print("Even")

    Question 9Python Match with No Case

    What will be the output?

    x = 100 match x: case 1: print("One") case 2: print("Two")

    Question 10Python Match with Guard (if condition)

    What will this code output?

    x = 5 match x: case n if n > 10: print("Greater than 10") case n if n < 10: print("Less than 10") case _: print("Equal to 10")