# #5 - Python Sets

<hr>
<h2 id=menu></h2>**Topics:**
<hr>
[1. Sets](#num1)<br>

<hr>
<h2 id=num1></h2>**1. Sets**
<hr>
[**>>Return to Menu**](#menu)<br>
**Set is one of Python's four built-in data types for storing collections of data; the other three are List, Tuple, and Dictionary, all of which have different properties and applications. **<br>
A set is a collection of items that is **unordered, unchangeable, and unindexed**. <br>Curly brackets are used to write sets.<br>
*Note: A Set is not a Dictionary!*

**- Unordered:**<br>
Items do not have a defined order, and that order will continually change every time you use them, and cannot be referred to by index or key. If you add new items to a set, the new items may not be placed at the end of the set.

**- Unchangeable:**<br>
We cannot change items in a set after it has been created. However, you can remove items and add new items.

**- Do not allow Duplicates:**<br>
Sets are unindexed, hence they cannot have two items with the same value or repeated items.

```
#empty Set
#empty_set = {} # this is wrong, this is a dictionary
empty_set = set()

friends_set = {'John','Michael','Terry','Eric','Graham'}
people_set = {'Eric','Reg','Loretta','Colin','Graham'}

#print a set
print(friends_set)
#Items that are found in both sets
print(friends_set.intersection(people_set))
print(friends_set & people_set)
#Items that are found in first but not second set
print(friends_set.difference(people_set))
print(friends_set - people_set)
#Items that are only found in one set
print(friends_set.symmetric_difference(people_set))
print(friends_set ^ people_set)
#Join two sets together
print(friends_set.union(people_set))
print(friends_set | people_set)
``` 
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1641816040863/FPIz-Lj89.png)


#End
<hr>
Hope you enjoyed this! :) Follow me for more contents...
<hr>
Get in Touch:<br>
www.ifeanyiomeata.com<br>
contact@ifeanyiomeata.com<br>

Youtube: https://www.youtube.com/c/IfeanyiOmeata<br>
Linkedin: https://www.linkedin.com/in/omeatai/<br>
Twitter: https://twitter.com/iomeata<br>
Github: https://github.com/omeatai/<br>
Stackoverflow: https://stackoverflow.com/users/2689166/omeatai<br>
Hashnode: https://hashnode.com/@omeatai<br>
Medium: https://medium.com/@omeatai<br>
© 2022



