exam questions

Exam PCEP-30-02 All Questions

View all questions & answers for the PCEP-30-02 exam

Exam PCEP-30-02 topic 1 question 33 discussion

Actual exam question from Python Institute's PCEP-30-02
Question #: 33
Topic #: 1
[All PCEP-30-02 Questions]

What is the expected output of the following code?

  • A. (1, 2)
  • B. The code is erroneous.
  • C. {'a':1, 'b':2}
  • D. [1,2]
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
hovnival
1 month, 2 weeks ago
Selected Answer: B
The correct answer is: B. The code is erroneous. Explanation: In the given code: data = {'a': 1, 'b': 2, 'c': 3} print(data['a', 'b']) data is a dictionary with keys 'a', 'b', and 'c'. When trying to access dictionary values, the key provided must be a single hashable object. In this case, ['a', 'b'] is a tuple (('a', 'b')), not a valid key in the dictionary. Since the dictionary data does not contain the key ('a', 'b'), Python raises a KeyError. Error: KeyError: ('a', 'b')
upvoted 1 times
...
FedeXD
4 months, 3 weeks ago
You can't index with multiple keys like this. You get a KeyError.
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago