Python Set Function


Python set () fucntion is used to create set object form any data type. With this method, we use this method to convert tuples or lists to sets for example.


Let’s show some examples that shows how to use set methos of python.


Below, we will convert a list to a set with the help of python set function.


dwarves2 =['Dwalin', 'Balin', 'Thorin']


The output of this function is a set as expected.


{'Balin', 'Thorin', 'Dwalin'}




We can do the similar job for tuples. Let’s convert the below number tuple to a set with the help of set method.


numbers1 = (3,6,8,12,15)


The output of this set function is like below:


{3, 6, 8, 12, 15}




Let’s give last examples with network devices:


devices = ["router", "switch", "access point", "firewall"]


{'switch', 'firewall', 'router', 'access point'}


Python set function is used to convert any data structure to a tuple. So, you can use this fucntion in your python codes sometimes.


Back to: Python Programming Course > Python Sets

Leave a Reply

Your email address will not be published. Required fields are marked *


IPCisco is the Winner! “Best Certification Study Journey of 2019!”