arrow
arrow
arrow
Considering the following dictionary: Num = {10: 'Ten', 100: 'Hundred', 10: 'Decimal'} What shall be the output of print(Num)?
Question

Considering the following dictionary:
Num = {10: 'Ten', 100: 'Hundred', 10: 'Decimal'}
What shall be the output of print(Num)?

A.

{10: 'Ten', 100: 'Hundred', 10: 'Decimal'}

B.

{10: 'Ten', 100: 'Hundred'}

C.

{10: 'Decimal', 100: 'Hundred'}

D.

Error

Correct option is C


In Python, dictionaries cannot have duplicate keys. When you try to add a key that already exists in the dictionary, it will update the value associated with that key.
Given the dictionary:
Num = {10: 'Ten', 100: 'Hundred', 10: 'Decimal'}
· The key 10 is repeated in the dictionary.
· The first occurrence of 10 is associated with the value 'Ten'.
· The second occurrence of 10 will overwrite the previous entry, and it will be associated with the value 'Decimal'.
Thus, the final dictionary will be:
{10: 'Decimal', 100: 'Hundred'}
Important Key Points:
1. No Duplicate Keys: In a dictionary, if the same key is repeated, the last value will overwrite the previous one.
2. Key-Value Pair: A dictionary stores data in key-value pairs, and each key must be unique.
Knowledge Booster:
Option (a): This is incorrect because duplicate keys are not allowed in a dictionary, so the second 10: 'Decimal' will overwrite the first 10: 'Ten'.
Option (b): This is incorrect because the second occurrence of 10 will overwrite the first one, so 'Ten' will not be present in the dictionary.

Free Tests

Free
Must Attempt

UPTET Paper 1: PYP Held on 23rd Jan 2022 (Shift 1)

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 Mins
languageIcon English
Free
Must Attempt

UPTET Paper 2 Social Science : PYP Held on 23rd Jan 2022 (Shift 2)

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 Mins
languageIcon English
Free
Must Attempt

UPTET Paper 2 Maths & Science : PYP Held on 23rd Jan 2022 (Shift 2)

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 Mins
languageIcon English
test-prime-package

Access ‘EMRS PGT’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
353k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow