0% found this document useful (0 votes)
10 views13 pages

Introduction to Python Sets

sets

Uploaded by

kumarn74858
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views13 pages

Introduction to Python Sets

sets

Uploaded by

kumarn74858
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Sets

Riya Jacob K
Assistant Professor on Contract
Dept of Computer Applications
Set
• A set is a collection which is unordered and
unindexed.
• In Python sets are written with curly brackets.
• # Note: the set list is unordered, meaning: the
items will appear in a random order.
Example
Create a Set:
thisset = {"apple", "banana", "cherry"}
print(thisset)
Output
{'cherry', 'banana', 'apple'}
• Output
apple
banana
cherry
• Output
True
• Output
{'orange', 'apple', 'banana', 'cherry'}
• Output
{'apple', 'grapes', 'mango', 'banana',
'cherry', 'orange'}
• Output
3
• Output
{'cherry', 'apple'}
• Output
{'cherry', 'apple'}
• Output
banana
{'apple', 'cherry'}
• Output
set()
• Output
Traceback (most recent call last):
File "demo_set_del.py", line 5, in <module>
print(thisset) #this will raise an error because the set no
longer exists
NameError: name 'thisset' is not defined

You might also like