hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    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

    CDP Subject Test 01

    languageIcon English
    • pdpQsnIcon20 Questions
    • pdpsheetsIcon20 Marks
    • timerIcon20 Mins
    languageIcon English
    Free
    Must Attempt

    EVS Subject Test 01

    languageIcon English
    • pdpQsnIcon20 Questions
    • pdpsheetsIcon20 Marks
    • timerIcon20 Mins
    languageIcon English
    Free
    Must Attempt

    CTET Paper-I PYP (07 July 2024)

    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
    289k+ students have already unlocked exclusive benefits with Test Prime!
    Our Plans
    Monthsup-arrow