Python - Loop Sets
Loop Items
You can loop through the set items by using a for
loop:
Example
Loop through the set, and print the values:
thisset = {"apple", "banana", "cherry"}
for x in thisset:
print(x)
Try it Yourself »
You can loop through the set items by using a for
loop:
Loop through the set, and print the values:
thisset = {"apple", "banana", "cherry"}
for x in thisset:
print(x)
Try it Yourself »
Ad-free learning, track your progress, earn XP, streaks, compete in leagues, build and host websites, unlock coding challenges, and much more!
If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com
If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com