Sets in Python

Sets in Python are used to store multiple items in a single variable. They are one of Python's built-in data types for storing collections of data. A set is a collection which is unordered and unindexed, and does not allow duplicate values.

Creating Sets

Sets are created by placing items inside curly braces {}.

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

Accessing Elements

Elements in a set can be accessed by iterating over it.

for item in my_set:
    print(item)

Updating Sets

Sets are mutable, meaning you can add and remove items.

my_set.add("orange")
print(my_set)