Python Test 4

    Question 1Python Complex Numbers

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

    Question 2Python Membership Operators

    What will be the output?

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

    Question 3Python List to String

    What will be the output of this code?

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

    Question 4Python Infinite While Loop

    Which of the following will create an infinite loop?

    Question 5Python Match Default Case

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

    Question 6Python Functions - Anonymous Functions

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

    Question 7Python Lists - Slicing

    What will this code output?

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

    Question 8Python Dictionaries - Updating Values

    What will be the output?

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

    Question 9Python Strings - len() Function

    What does the following return?

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

    Question 10Python OOPs - Method Overriding

    What is method overriding?

    Question 11Python Type Checking

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

    Question 12Python Bitwise Operator

    What is the result of 6 & 3?

    Question 13Python Float String Conversion

    What is the output of this code?

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

    Question 14Python Nested Loop

    What will be the output?

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

    Question 15Python Match Multiple Patterns

    What will this code print?

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

    Question 16Python Functions - Built-in map()

    What will be the output?

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

    Question 17Python Lists - Nested Lists

    What is the output?

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

    Question 18Python Sets - Union Operation

    What is the output?

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

    Question 19Python Strings - String Methods

    What will this output?

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

    Question 20Python OOPs - self Keyword

    What is the purpose of self in a class method?