Learn practical skills, build real-world projects, and advance your career

Set

A set is a collection which is unordered and unindexed. In Python, sets are written with curly brackets.

thisset = {"apple", "banana", "cherry"}
print(thisset)

# Note: Sets are unordered, so you cannot be sure in which order the items will appear.
{'apple', 'cherry', 'banana'}
thisset = {"apple", "banana", "cherry"}

for x in thisset:
  print(x)
apple cherry banana
thisset = {"apple", "banana", "cherry"}

print("banana" in thisset)
True
# add items 

thisset = {"apple", "banana", "cherry"}

thisset.add("orange")

print(thisset)
{'apple', 'cherry', 'orange', 'banana'}