Python Test 5

    Question 1: Python Multiple Assignment

    What will be the output of this code?

    a, b, c = 1, 2, 3 print(a + b + c)

    Question 2: Python Operator Precedence

    What will be the output of this code?

    x = 2 + 3 * 4 print(x)

    Question 3: Python Complex Number Casting

    What will be the result of the following?

    x = complex(5) print(x)

    Question 4: Python Iterating Over String

    What will this code output?

    for ch in "Hi": print(ch, end="-")

    Question 5: Python Match with No Case

    What will be the output?

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

    Question 6: Python Functions - Recursive Function

    What will be the output?

    def factorial(n): if n == 0: return 1 else: return n * factorial(n-1) print(factorial(3))

    Question 7: Python Tuples - Concatenation

    What will this code print?

    t1 = (1, 2) t2 = (3, 4) print(t1 + t2)

    Question 8: Python Sets - Membership

    What will this code print?

    s = {1, 2, 3} print(4 in s)

    Question 9: Python Strings - in Operator

    What will this code print?

    s = "Python" print("tho" in s)

    Question 10: Python OOPs - super()

    What is the purpose of super() in Python?

    Question 11: Python None Type

    What will be the output?

    x = None print(type(x))

    Question 12: Python Augmented Assignment

    What is the output of the code?

    x = 5 x += 3 print(x)

    Question 13: Python Automatic Type Conversion

    What will be the output of this expression?

    x = 10 + 3.5 print(type(x))

    Question 14: Python Range with Negative Step

    What will be the output?

    for i in range(5, 0, -2): print(i, end=" ")

    Question 15: Python 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")

    Question 16: Python Functions - *args Usage

    What will be the output?

    def add(*args): return sum(args) print(add(1, 2, 3, 4))

    Question 17: Python Lists - Length

    What is the output?

    lst = [10, 20, 30, 40] print(len(lst))

    Question 18: Python Dictionaries - Iterating Keys

    What will this code output?

    d = {"a": 1, "b": 2} for key in d: print(key, end=" ")

    Question 19: Python Strings - strip() Method

    What will this code output?

    s = " Hello " print(s.strip())

    Question 20: Python OOPs - Encapsulation

    Which of the following demonstrates encapsulation?