You cannot access items in a set by referring to an index, since sets are unordered the items has no index.
But you can loop through the set items using a for
loop, or ask if a specified value is present in a set, by using the in
keyword.
Loop through the set, and print the values:
thisset = {"apple", "banana", "cherry"}
for x in thisset:
print(x)
Try it Yourself » ExampleCheck if "banana" is present in the set:
thisset = {"apple", "banana", "cherry"}
print("banana" in thisset)
Try it Yourself »Track your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4