Python Programming
About Lesson

The set data structure of Python is a list of data elements stored in unordered or no index manner. Set is created using pair of curly braces.

#Example code to create a Set
fruits = {“apple”, “banana”, “cherry”}
print(fruits)

Access Items
Since set is not maintain any index, we cannot access elements of set using index values. But we can search for the presence of a data element by its value.

#Check if “banana” is present in the set:
fruits = {“apple”, “banana”, “cherry”}
print(“banana” in fruits)

You cannot copy content of this page