LearnFrenzy
Sign in Take a free test

Dictionaries · Predict the Output · Question 4

1, True and 1.0 as keys Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

What is the output of the following Python program?

main.py
d = {1: "int", True: "bool", 1.0: "float"}
print(d, len(d))
  • A {1: 'float'} 1 Correct
  • B {1: 'int', True: 'bool', 1.0: 'float'} 3
  • C {True: 'bool'} 1
  • D {1.0: 'float'} 1
Correct Answer: Option A

The three keys are equal with equal hashes, so they are one key. The first key object (1) is kept and each assignment replaces the value, ending with "float".

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links