Python Test 5

    Question 1Python Multiple Assignment

    What will be the output of this code?

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

    Question 2Python Operator Precedence

    What will be the output of this code?

    x = 2 + 3 * 4 print(x)

    Question 3Python Complex Number Casting

    What will be the result of the following?

    x = complex(5) print(x)

    Question 4Python Iterating Over String

    What will this code output?

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

    Question 5Python Match with No Case

    What will be the output?

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

    Question 6Python 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 7Python Tuples - Concatenation

    What will this code print?

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

    Question 8Python Sets - Membership

    What will this code print?

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

    Question 9Python Strings - in Operator

    What will this code print?

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

    Question 10Python OOPs - super()

    What is the purpose of super() in Python?

    Question 11Python None Type

    What will be the output?

    x = None print(type(x))

    Question 12Python Augmented Assignment

    What is the output of the code?

    x = 5 x += 3 print(x)

    Question 13Python Automatic Type Conversion

    What will be the output of this expression?

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

    Question 14Python Range with Negative Step

    What will be the output?

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

    Question 15Python 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 16Python Functions - *args Usage

    What will be the output?

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

    Question 17Python Lists - Length

    What is the output?

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

    Question 18Python Dictionaries - Iterating Keys

    What will this code output?

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

    Question 19Python Strings - strip() Method

    What will this code output?

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

    Question 20Python OOPs - Encapsulation

    Which of the following demonstrates encapsulation?