Python Test 4

    Question 1: Python Complex Numbers

    Which is the correct way to declare a complex number in Python?

    Question 2: Python Membership Operators

    What will be the output?

    x = "Python" print("th" in x)

    Question 3: Python List to String

    What will be the output of this code?

    x = str([1, 2, 3]) print(x)

    Question 4: Python Infinite While Loop

    Which of the following will create an infinite loop?

    Question 5: Python Match Default Case

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

    Question 6: Python Functions - Anonymous Functions

    Which of the following correctly defines a lambda function to double a number?

    Question 7: Python Lists - Slicing

    What will this code output?

    lst = [0, 1, 2, 3, 4] print(lst[1:4])

    Question 8: Python Dictionaries - Updating Values

    What will be the output?

    d = {"a": 1} d["a"] = 5 print(d)

    Question 9: Python Strings - len() Function

    What does the following return?

    s = "Python" print(len(s))

    Question 10: Python OOPs - Method Overriding

    What is method overriding?

    Question 11: Python Type Checking

    Which function is used to check the type of a variable in Python?

    Question 12: Python Bitwise Operator

    What is the result of 6 & 3?

    Question 13: Python Float String Conversion

    What is the output of this code?

    x = float("12.34") print(x + 1)

    Question 14: Python Nested Loop

    What will be the output?

    for i in range(2): for j in range(2): print(i, j, end=" ")

    Question 15: Python Match Multiple Patterns

    What will this code print?

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

    Question 16: Python Functions - Built-in map()

    What will be the output?

    nums = [1, 2, 3] result = list(map(lambda x: x * 2, nums)) print(result)

    Question 17: Python Lists - Nested Lists

    What is the output?

    lst = [[1, 2], [3, 4]] print(lst[1][0])

    Question 18: Python Sets - Union Operation

    What is the output?

    s1 = {1, 2} s2 = {2, 3} print(s1 | s2)

    Question 19: Python Strings - String Methods

    What will this output?

    s = "python" print(s.upper())

    Question 20: Python OOPs - self Keyword

    What is the purpose of self in a class method?