Python Test 3

    Question 1: Python Type Casting

    What will be the output?

    x = int(3.9) print(x)

    Question 2: Python Logical Operators

    What will be the result of the expression?

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

    Question 3: Python Boolean to Integer

    What will be the output of this code?

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

    Question 4: Python Continue Statement

    What is the output?

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

    Question 5: Python Match Statement

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

    Question 6: Python Functions - Scope of Variables

    What will be the output?

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

    Question 7: Python Lists - Append Method

    What is the output?

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

    Question 8: Python Sets - Creation

    Which of the following correctly creates a set?

    Question 9: Python Strings - Concatenation

    What will this code print?

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

    Question 10: Python OOPs - Class Variables

    Which of the following is a class variable?

    class Test: y = 10

    Question 11: Python Dynamic Typing

    What is the output of the code below?

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

    Question 12: Python Identity Operators

    What is the output of this code?

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

    Question 13: Python Integer to Boolean

    What will be the output?

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

    Question 14: Python Else with Loop

    What will be the output?

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

    Question 15: Python Match with Cases

    What will this code output?

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

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

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

    Question 17: Python Tuples - Single Element

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

    Question 18: Python Sets - Uniqueness

    What will this code output?

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

    Question 19: Python Strings - Repetition

    What will be the output?

    s = "Hi" print(s * 3)

    Question 20: Python OOPs - Inheritance

    Which syntax correctly inherits class Parent in a class Child?