350-601 · Question #575
350-601 Question #575: Real Exam Question with Answer & Explanation
The correct answer is A: interface_name = json_object["if-name"]. To retrieve the network interface name 'eth0' from the Python dictionary json_object, access the dictionary using its corresponding key, which is 'if-name'.
Question
Refer to the exhibit. A network engineer must retrieve the network interface name from a JSON object. The engineer loads the JSON into a Python dictionary named json_object. Which code snippet completes the Python script?
Options
- Ainterface_name = json_object["if-name"]
- Binterface_name = json_object[0]
- Cinterface_name = json_object["eth0"]
- Dinterface_name = json_object[0][2]
Explanation
To retrieve the network interface name 'eth0' from the Python dictionary json_object, access the dictionary using its corresponding key, which is 'if-name'.
Common mistakes.
- B.
json_object[0]attempts to access the dictionary using a numeric index, which is not valid for Python dictionaries as they are not ordered sequences. - C.
json_object["eth0"]attempts to use the value "eth0" as a key, which would result in a KeyError because "eth0" is not a key in the dictionary. - D.
json_object[0][2]attempts to access a dictionary by a numeric index and then further index an element, which is entirely incorrect for this simple key-value JSON structure.
Concept tested. Python dictionary access for JSON data
Reference. https://docs.python.org/3/library/json.html
Topics
Community Discussion
No community discussion yet for this question.