WGU D522 |OA| OBJECTIVE
ASSESSMENT (LATEST UPDATE)
PYTHON FOR IT AUTOMATION| EXAM
QUESTIONS AND ANSWERS
1. What is the primary advantage of using dictionaries in Python?
A. They store data in sorted order
B. They allow key–value associations
C. They allow duplicate keys
D. They store only numeric data
✅ Correct Answer: B
Explanation:
Dictionaries allow values to be associated with descriptive keys, making data easy to
access and manage. This structure is ideal for representing relationships such as device
names and IP addresses. Dictionaries are widely used in IT automation because they
improve readability and efficiency. Keys must be unique, but values can be duplicated.
2. Which symbol is used to define a dictionary in Python?
A. []
B. ()
C. {}
D. <>
✅ Correct Answer: C
Explanation:
Python dictionaries are defined using curly braces {}. Inside the braces, key–value pairs
are separated by commas. Each key is separated from its value using a colon. This syntax
,distinguishes dictionaries from lists and tuples.
3. Which of the following is a valid dictionary key type?
A. List
B. Dictionary
C. Tuple
D. Set
✅ Correct Answer: C
Explanation:
Dictionary keys must be immutable, meaning they cannot change after creation. Tuples
are immutable and therefore valid dictionary keys. Lists and dictionaries are mutable
and cannot be used as keys. Sets are also mutable and invalid as keys.
4. What will happen if duplicate keys are used in a dictionary?
A. Python raises an error
B. Both values are stored
C. The first value is kept
D. The last value overwrites the earlier one
✅ Correct Answer: D
Explanation:
When duplicate keys are used, Python keeps only the last assigned value. The earlier
value is overwritten without warning. This behavior ensures each key remains unique.
Developers must be careful to avoid unintentional overwrites.
5. Which method is used to retrieve all keys from a dictionary?
A. getkeys()
B. keys()
C. values()
D. items()
✅ Correct Answer: B
,Explanation:
The keys() method returns a view object containing all dictionary keys. This is useful
when iterating through keys in automation scripts. The returned object updates
dynamically if the dictionary changes. It does not return values or key–value pairs.
6. What does the values() method return?
A. Only dictionary keys
B. Only dictionary values
C. Key–value pairs
D. Sorted dictionary
✅ Correct Answer: B
Explanation:
The values() method returns all values stored in a dictionary. It does not include keys.
This method is helpful when analyzing or processing stored data without needing the
keys. The returned object reflects live changes to the dictionary.
7. How do you safely access a dictionary value without raising an
error?
A. Using square brackets
B. Using find()
C. Using get()
D. Using search()
✅ Correct Answer: C
Explanation:
The get() method allows safe access to dictionary values. If the key does not exist, it
returns None or a specified default value instead of raising an error. This is especially
useful in automation scripts where missing keys are possible. It improves script stability.
8. What will dict.get("missing") return if the key does not exist?
, A. Error
B. 0
C. Empty string
D. None
✅ Correct Answer: D
Explanation:
If a key is not found, the get() method returns None by default. This prevents runtime
errors and allows the script to continue running. A custom default value can also be
specified. This behavior is safer than direct indexing.
9. How can you add a new key-value pair to a dictionary?
A. Using append()
B. Using add()
C. Assigning a value to a new key
D. Using insert()
✅ Correct Answer: C
Explanation:
A new key-value pair is added by directly assigning a value to a new key. Python
automatically adds the key if it does not exist. This approach is simple and efficient. It is
commonly used in configuration automation.
10. What does the update() method do in a dictionary?
A. Deletes keys
B. Adds or modifies key-value pairs
C. Sorts the dictionary
D. Copies the dictionary
✅ Correct Answer: B
Explanation:
The update() method merges another dictionary into the current one. Existing keys are
updated, and new keys are added. This is useful when combining configuration data. It
ASSESSMENT (LATEST UPDATE)
PYTHON FOR IT AUTOMATION| EXAM
QUESTIONS AND ANSWERS
1. What is the primary advantage of using dictionaries in Python?
A. They store data in sorted order
B. They allow key–value associations
C. They allow duplicate keys
D. They store only numeric data
✅ Correct Answer: B
Explanation:
Dictionaries allow values to be associated with descriptive keys, making data easy to
access and manage. This structure is ideal for representing relationships such as device
names and IP addresses. Dictionaries are widely used in IT automation because they
improve readability and efficiency. Keys must be unique, but values can be duplicated.
2. Which symbol is used to define a dictionary in Python?
A. []
B. ()
C. {}
D. <>
✅ Correct Answer: C
Explanation:
Python dictionaries are defined using curly braces {}. Inside the braces, key–value pairs
are separated by commas. Each key is separated from its value using a colon. This syntax
,distinguishes dictionaries from lists and tuples.
3. Which of the following is a valid dictionary key type?
A. List
B. Dictionary
C. Tuple
D. Set
✅ Correct Answer: C
Explanation:
Dictionary keys must be immutable, meaning they cannot change after creation. Tuples
are immutable and therefore valid dictionary keys. Lists and dictionaries are mutable
and cannot be used as keys. Sets are also mutable and invalid as keys.
4. What will happen if duplicate keys are used in a dictionary?
A. Python raises an error
B. Both values are stored
C. The first value is kept
D. The last value overwrites the earlier one
✅ Correct Answer: D
Explanation:
When duplicate keys are used, Python keeps only the last assigned value. The earlier
value is overwritten without warning. This behavior ensures each key remains unique.
Developers must be careful to avoid unintentional overwrites.
5. Which method is used to retrieve all keys from a dictionary?
A. getkeys()
B. keys()
C. values()
D. items()
✅ Correct Answer: B
,Explanation:
The keys() method returns a view object containing all dictionary keys. This is useful
when iterating through keys in automation scripts. The returned object updates
dynamically if the dictionary changes. It does not return values or key–value pairs.
6. What does the values() method return?
A. Only dictionary keys
B. Only dictionary values
C. Key–value pairs
D. Sorted dictionary
✅ Correct Answer: B
Explanation:
The values() method returns all values stored in a dictionary. It does not include keys.
This method is helpful when analyzing or processing stored data without needing the
keys. The returned object reflects live changes to the dictionary.
7. How do you safely access a dictionary value without raising an
error?
A. Using square brackets
B. Using find()
C. Using get()
D. Using search()
✅ Correct Answer: C
Explanation:
The get() method allows safe access to dictionary values. If the key does not exist, it
returns None or a specified default value instead of raising an error. This is especially
useful in automation scripts where missing keys are possible. It improves script stability.
8. What will dict.get("missing") return if the key does not exist?
, A. Error
B. 0
C. Empty string
D. None
✅ Correct Answer: D
Explanation:
If a key is not found, the get() method returns None by default. This prevents runtime
errors and allows the script to continue running. A custom default value can also be
specified. This behavior is safer than direct indexing.
9. How can you add a new key-value pair to a dictionary?
A. Using append()
B. Using add()
C. Assigning a value to a new key
D. Using insert()
✅ Correct Answer: C
Explanation:
A new key-value pair is added by directly assigning a value to a new key. Python
automatically adds the key if it does not exist. This approach is simple and efficient. It is
commonly used in configuration automation.
10. What does the update() method do in a dictionary?
A. Deletes keys
B. Adds or modifies key-value pairs
C. Sorts the dictionary
D. Copies the dictionary
✅ Correct Answer: B
Explanation:
The update() method merges another dictionary into the current one. Existing keys are
updated, and new keys are added. This is useful when combining configuration data. It