Programming Language Python Set MCQ Question #3808
Single Choice Not Set

QWhat is the output of the following code
sampleSet = {"Yellow", "Orange", "Black"}
print(sampleSet[1])

ID: #3808 Python Set MCQ 233 views
Question Info
#3808Q ID
Not SetDifficulty
Python Set MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A Yellow
  • B Syntax Error
  • C Orange
Correct Answer

Explanation

Syntax Error

We cannot access items in a set by referring to an index because the ‘set’ object does support indexing (the set is unordered). if you try to access items using the index, you will get TypeError: ‘set’ object does not support indexing.

Use a for loop to access set items.

sampleSet = {"Yellow", "Orange", "Black"}
for item in sampleSet:
  print(item)

Share This Question

Challenge a friend or share with your study group.