Computers

University

Image

Python Dictionaries

43
plays

10 questions

Show Answers
See Preview
  • 1. Multiple Choice
    20 seconds
    1 pt

    Which of the following are true of Python dictionaries:

    Dictionaries can be nested to any depth.

    Dictionaries are accessed by key.

    All the keys in a dictionary must be of the same type.

    Dictionaries are mutable.

    A dictionary can contain any object type except another dictionary.

  • 2. Multiple Choice
    20 seconds
    1 pt

    Which of the following is not a valid way to define this dictionary in Python:

    d = dict([

    ('foo', 100),

    ('bar', 200),

    ('baz', 300)

    ])

    d = {}

    d['foo'] = 100

    d['bar'] = 200

    d['baz'] = 300

    d = dict(foo=100, bar=200, baz=300)

    d = {'foo': 100, 'bar': 200, 'baz': 300}

    d = { ('foo', 100), ('bar', 200), ('baz', 300) }

  • 3. Multiple Choice
    20 seconds
    1 pt

    Consider this dictionary:


    d = {'foo': 100, 'bar': 200, 'baz': 300}


    What is the result of this statement:


    d['bar':'baz']

    It raises an exception

    (200, 300)

    200 300

    [200, 300]

  • Answer choices
    Tags
    Answer choices
    Tags

    Explore all questions with a free account

    Already have an account?