Articles → Python → Sets In Python

Sets In Python






Purpose





Example


mySet = {1,2,3,4,5,2}

print(mySet)




Picture showing the output of sets in python



Add Duplicate Elements In Sets




mySet = {1,2,3,4,5}

mySet.add(1)

print(mySet)




Picture showing the output of sets in python



Converting The List To Set




mySet = {1,2,3,4,5}

myList = [1,2,1]

print(set(myList))



Output


Picture showing the output of converting list to set in python



Posted By  -  Karan Gupta
 
Posted On  -  Thursday, March 7, 2019

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250