Quiz Created Dec 31, 2025

Predict the Output - Python Questions

Safar Ruhi 25 Questions ~25 min 2 Participants

About this Quiz

This comprehensive Python quiz contains 25 carefully crafted questions designed to test your understanding of Python output prediction. Each question presents a Python code snippet and asks you to predict the exact output. This quiz covers fundamental Python concepts including:

• Basic operations (arithmetic, string operations, comparisons)
• Data types and their behaviors (int, str, list, bool)
• Built-in functions (len, type, print)
• String slicing and indexing
• Boolean logic and operations
• List operations and methods
• Dictionary operations
• Conditional statements
• Loop behaviors
• Variable assignments and scope

By completing this quiz, you'll strengthen your ability to trace code execution mentally, which is crucial for writing bug-free Python programs and performing well in technical interviews.

Q1 / 25

Multiple Choice

What will be the output of the following code?

x = 5
y = x
print(x is y)

Q2 / 25

Multiple Choice

def gen():
    yield 1
    yield 2
    return "stopped"

x = list(gen())
print(x)

Q3 / 25

Multiple Choice

def gen():
    for i in range(3):
        yield i

g = gen()
print(next(g))
print(list(g))

Q4 / 25

Multiple Choice

What is the output?

x = "python"
print(x[0:3])

Q5 / 25

Multiple Choice

Predict Output:

print(type(5))

Q6 / 25

Multiple Choice

Output:
print(len([1,2,3]))

Q7 / 25

Multiple Choice

Output:
print(True and False)

Q8 / 25

Multiple Choice

Output:
print('a' * 2 + 'b')

Q9 / 25

Multiple Choice

Output:
print(10 // 3)

Q10 / 25

Multiple Choice

Output:
print([1,2][1])

Q11 / 25

Multiple Choice

Output:
print('x' if 5 > 3 else 'y')

Q12 / 25

Multiple Choice

Output:
print(10 % 3)

Q13 / 25

Multiple Choice

Output:
print('Hello'.upper())

Q14 / 25

Multiple Choice

Output:
print(not True)

Q15 / 25

Multiple Choice

Output:
print(2 ** 3)

Q16 / 25

Multiple Choice

Mutable Default Argument

def add_item(item, lst=[]):
    lst.append(item)
    return lst

print(add_item(1))
print(add_item(2))
print(add_item(3))

Q17 / 25

Multiple Choice

List vs Generator

x = [i*i for i in range(3)]
y = (i*i for i in range(3))

print(next(y))
print(next(y))
print(x)

Q18 / 25

Multiple Choice

Output:
print('ab' in 'abc')

Q19 / 25

Multiple Choice

Variable Shadowing

x = 10

def test():
    print(x)
    x = 5

test()

Q20 / 25

Multiple Choice

Output:
print(min(1,5,3))

Q21 / 25

Multiple Choice

Predict Output:

x = {'a': 1, 'b': 2}
print(list(x.keys()))

Q22 / 25

Multiple Choice

Predict Output:

def func(x=[]):
    x.append(1)
    return x

print(func())
print(func())

Q23 / 25

Multiple Choice

Predict Output:

print([x*2 for x in [1,2,3]])

Q24 / 25

Multiple Choice

Predict Output:

print(sum([1, 2, 3, 4]))

Q25 / 25

Multiple Choice

Predict Output:

for i in range(3):
    print(i, end=' ')

Previous
End of questions

Authentication Required

You need to be logged in to attempt this quiz