nerdexam
CiscoCisco

350-601 · Question #409

350-601 Question #409: Real Exam Question with Answer & Explanation

The correct answer is D: switch_id_list.update({"N9K-Spine-2": "1498323434"}). To add a new key-value pair to an existing Python dictionary named switch_id_list, the update() method is the correct approach for merging the new dictionary element.

Automation

Question

An engineer implements a Python script inside a Cisco Bash shell. The script contains this dictionary object: Which command must be used to add the 'NSK-Spine-2': `1498323434' element to the switch_id list dictionary?

Options

  • Aswitch_id_list += {"N9K-Spine-2": "1498323434"}
  • Bswitch_id_list = ["N9K-Spine-2": "1498323434"]
  • Cswitch_id_list.append({"N9K-Spine-2": "1498323434"})
  • Dswitch_id_list.update({"N9K-Spine-2": "1498323434"})

Explanation

To add a new key-value pair to an existing Python dictionary named switch_id_list, the update() method is the correct approach for merging the new dictionary element.

Common mistakes.

  • A. The += operator is not used for merging dictionaries in this manner; it typically performs in-place addition for lists or concatenation for strings, and would result in a TypeError for dictionaries.
  • B. Assigning a new dictionary using = would overwrite the existing switch_id_list dictionary, not add an element to it, and the syntax ["N9K-Spine-2": "1498323434"] is incorrect for creating a dictionary.
  • C. The append() method is used to add an item to the end of a list, not to merge elements into a dictionary. If switch_id_list were a list, append would be applicable, but the question states it's a dictionary object.

Concept tested. Python dictionary manipulation (update method)

Reference. https://docs.python.org/3/library/stdtypes.html#dict.update

Topics

#Python#Dictionaries#Data Structures#Automation Scripting

Community Discussion

No community discussion yet for this question.

Full 350-601 PracticeBrowse All 350-601 Questions