Set is disorder ( No index ), Sets that do not duplicate . stay Python in , Sets are written in curly braces , Similar to the set in Mathematics .
Be careful :
have access to
Curly braces { }
perhaps set() Function to create a collection , But to create an empty collection, you must use set() instead of { }, because { } Is used to create an empty dictionary ,
# Define a set
s1={
1,2,3,4,5,5,6,7,7}
print(s1)
{1, 2, 3, 4, 5, 6, 7}
# Delete an element
s1.remove(7)
print(s1)
{1, 2, 3, 4, 5, 6}
# To find the intersection of sets &, Combine \
s2={
1,2,4,5,6,8}
print(s1&s2)
{1, 2, 4, 5, 6}
print(s1|s2)
{1, 2, 3, 4, 5, 6, 8}
#set Method : Convert a string to a collection
string1='Python'
s1=set(string1)
print(s1)
{‘h’, ‘P’, ‘o’, ‘y’, ‘n’, ‘t’}