LearnFrenzy
Sign in Take a free test

Tricky Python Output Questions · Exercise 1 of 4

Tricky Python Output Questions Tricky Python Concepts MCQ

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

Ten multiple-choice questions on the rules behind tricky Python outputs: references, defaults, late binding, rounding, floor division, truthiness and evaluation order. Pick an option to check your answer instantly.

Question 1 Easy

After b = a where a is a list, which statement is true?

A b is an independent copy
B a and b refer to the same list, so changes made through one are visible through the other
C b is a tuple version of a
D a is cleared
Question page & discussion
Question 2 Medium

Why does def f(x, acc=[]) keep data between calls?

A Python caches all function results
B acc is a global variable
C The default list is created once, when def runs, and reused by every call that omits acc
D It does not keep data
Question page & discussion
Question 3 Hard

When does a lambda created inside a loop read the loop variable?

A When the lambda is created
B When the lambda is called
C When the loop starts
D Never – it copies all variables
Question page & discussion
Question 4 Medium

What are round(1.5) and round(2.5)?

A 2 and 2
B 2 and 3
C 1 and 2
D 1.5 and 2.5
Question page & discussion
Question 5 Medium

What are -7 // 2 and int(-7 / 2)?

A -4 and -3
B -3 and -3
C -4 and -4
D -3 and -4
Question page & discussion
Question 6 Medium

What is the value of "" or [] or 0?

A 0
B False
C ""
D None
Question page & discussion
Question 7 Easy

What does print([3, 1, 2].sort()) print?

A None
B [1, 2, 3]
C [3, 1, 2]
D An error
Question page & discussion
Question 8 Hard

How many keys does {1: "a", 1.0: "b", True: "c"} have?

A 3
B 2
C 1
D It raises TypeError
Question page & discussion
Question 9 Medium

Which expression is True?

A not []
B [] == False
C [] is False
D [] == None
Question page & discussion
Question 10 Medium

A generator expression g is passed to sum() twice. What does the second call return?

A 0, because the generator was exhausted by the first call
B The same total again
C TypeError
D None
Question page & discussion
Up next · Exercise 2Tricky Output Questions – Core Python15 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links