LearnFrenzy
Sign in Take a free test

Tricky Python Output Questions · Exercise 2 of 4

Tricky Python Output Questions Tricky Output Questions – Core Python

  • 15 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Fifteen tricky predict-the-output questions on core Python: references, numbers, strings and slicing, truthiness, dictionaries and unpacking. Every program was run on Python 3, so the answers are the real output.

Question 1 Easy

What is the output of the following Python program?

main.py
print(type(print("hi")))
A <class 'str'>
B hi <class 'str'>
C hi <class 'NoneType'>
D <class 'NoneType'>
Question page & discussion
Question 2 Medium

What is the output of the following Python program?

main.py
x = [1, 2, 3]
y = x
x = x + [4]
x += [5]
print(y, x)
A [1, 2, 3] [1, 2, 3, 4, 5]
B [1, 2, 3, 4, 5] [1, 2, 3, 4, 5]
C [1, 2, 3, 5] [1, 2, 3, 4, 5]
D [1, 2, 3, 4] [1, 2, 3, 4, 5]
Question page & discussion
Question 3 Easy

What is the output of the following Python program?

main.py
print(repr("abc" * 0), [0] * 3, "-".join("abc"), "ab" * -1 == "")
A 'abc' [0, 0, 0] a-b-c False
B '' [0] a-b-c True
C '' [0, 0, 0] a-b-c True
D '' [0, 0, 0] -a-b-c- True
Question page & discussion
Question 4 Medium

What is the output of the following Python program?

main.py
print(10 / 4, 10 // 4, -10 // 4, 10 % -4)
A 2.5 2 -2 2
B 2 2 -3 -2
C 2.5 2 -3 -2
D 2.5 2.0 -3 2
Question page & discussion
Question 5 Medium

What is the output of the following Python program?

main.py
print(1 < 2 > 1.5 == 1.5, 5 > 3 > 1, 2 < 3 < 1, (2 < 3) < 1)
A True True False True
B False True False False
C True True False False
D True False False False
Question page & discussion
Question 6 Medium

What is the output of the following Python program?

main.py
print([] == False, bool([]) == False, not [], [] is not None)
A False True True True
B True True True True
C False False True True
D True True False True
Question page & discussion
Question 7 Easy

What is the output of the following Python program?

main.py
print("5" + "5", 5 + 5, "5" * 2, int("5") * 2, "5" < "10")
A 10 10 10 10 True
B 55 10 55 10 False
C 55 10 55 10 True
D 55 10 10 10 False
Question page & discussion
Question 8 Medium

What is the output of the following Python program?

main.py
a = [1, 2, 3]
print(a[-1:], a[5:], a[::-2], a[1:1], a[-5:2])
A 3 [] [3, 1] [] [1, 2]
B [3] IndexError
C [3] [] [1, 3] [2] [1, 2]
D [3] [] [3, 1] [] [1, 2]
Question page & discussion
Question 9 Medium

What is the output of the following Python program?

main.py
s = "Python"
print(s[1:4:2], s[-3:], s[:-3], s[::-1][::2])
A yth hon Pyt nhy
B yh hon Pyth nhy
C yh on Pyt otP
D yh hon Pyt nhy
Question page & discussion
Question 10 Hard

What is the output of the following Python program?

main.py
d = {}
d[1] = "a"
d[1.0] = "b"
d[True] = "c"
print(d, len(d))
A {1: 'c'} 1
B {1: 'a', 1.0: 'b', True: 'c'} 3
C {True: 'c'} 1
D {1.0: 'c'} 1
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links