Python Test 2

    Question 1Python String Type in Python

    Which of the following is a valid string declaration in Python?

    Question 2Python Modulus Operator

    What is the result of -7 % 3 in Python?

    Question 3Python String to Integer Conversion

    What will be the output?

    x = int("25") print(x + 5)

    Question 4Python Step in Range

    What is the output?

    for i in range(1, 10, 3): print(i, end=" ")

    Question 5Python Nested If

    What will be printed?

    x = 15 if x > 10: if x < 20: print("Between 10 and 20")

    Question 6Python Functions - Return Statement

    What will be the output?

    def add(a, b): return a + b print(add(2, 3) * 2)

    Question 7Python Lists - Indexing

    What will this code output?

    lst = [10, 20, 30] print(lst[1])

    Question 8Python Dictionaries - get() Method

    What is the output?

    d = {"x": 5} print(d.get("y", 0))

    Question 9Python Strings - Negative Index

    What is the output?

    s = "Python" print(s[-1])

    Question 10Python OOPs - Constructor

    Which method is the constructor in Python?

    Question 11Python Boolean Data Type

    What will be the output of the following code?

    x = True print(type(x))

    Question 12Python Comparison Operator

    What is the output of this code?

    print(5 == 5.0)

    Question 13Python Invalid Casting

    What happens when we execute the following?

    x = int("Python")

    Question 14Python Break Statement

    What will be the output?

    for i in range(5): if i == 3: break print(i, end=" ")

    Question 15Python If with Boolean Expression

    What will this code print?

    x = 5 if x and 10: print("Yes") else: print("No")

    Question 16Python Functions - Keyword Arguments

    Which function call is valid for the following definition?

    def student(name, age): print(name, age)

    Question 17Python Lists - Negative Index

    What does lst[-1] return?

    lst = [1, 2, 3, 4]

    Question 18Python Dictionaries - Keys

    Which of the following can be used as a dictionary key?

    Question 19Python Strings - Slicing

    What will this code output?

    s = "Python" print(s[1:4])

    Question 20Python OOPs - Instance Variables

    What will this code print?

    class Test: def __init__(self, x): self.x = x obj = Test(5) print(obj.x)