Python Test 3

    Question 1Python Type Casting

    What will be the output?

    x = int(3.9) print(x)

    Question 2Python Logical Operators

    What will be the result of the expression?

    x = True y = False print(x and not y)

    Question 3Python Boolean to Integer

    What will be the output of this code?

    print(int(True), int(False))

    Question 4Python Continue Statement

    What is the output?

    for i in range(5): if i == 2: continue print(i, end=" ")

    Question 5Python Match Statement

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

    Question 6Python Functions - Scope of Variables

    What will be the output?

    x = 10 def test(): x = 20 print(x) test() print(x)

    Question 7Python Lists - Append Method

    What is the output?

    lst = [1, 2] lst.append(3) print(lst)

    Question 8Python Sets - Creation

    Which of the following correctly creates a set?

    Question 9Python Strings - Concatenation

    What will this code print?

    s1 = "Hello" s2 = "World" print(s1 + " " + s2)

    Question 10Python OOPs - Class Variables

    Which of the following is a class variable?

    class Test: y = 10

    Question 11Python Dynamic Typing

    What is the output of the code below?

    x = 10 x = "Python" print(x)

    Question 12Python Identity Operators

    What is the output of this code?

    x = [1, 2, 3] y = [1, 2, 3] print(x is y)

    Question 13Python Integer to Boolean

    What will be the output?

    print(bool(0), bool(5))

    Question 14Python Else with Loop

    What will be the output?

    for i in range(3): print(i, end=" ") else: print("Done")

    Question 15Python Match with Cases

    What will this code output?

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

    Question 16Python Functions - Built-in max()

    What will max([3, 7, 2, 9, 5]) return?

    Question 17Python Tuples - Single Element

    Which of the following correctly creates a tuple with a single element 5?

    Question 18Python Sets - Uniqueness

    What will this code output?

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

    Question 19Python Strings - Repetition

    What will be the output?

    s = "Hi" print(s * 3)

    Question 20Python OOPs - Inheritance

    Which syntax correctly inherits class Parent in a class Child?