Python Set() function

Published February 16, 2022

The set() function converts an iterable to a sequence of iterable items containing distinct elements, which is known as a Set.
Syntax of set() Function

The set() method is written as follows

Set(iterable)

Where, the iterable can comprise a dictionary, a list or a turple


Example

x = { 3 : 'I', 2 : 'Love', 1 : 'Python' }
print("Before coversion : " + str(x))
print("After conversion : " + str(set(x)))

Output

Before coversion : {3: 'I', 2: 'Love', 1: 'Python'}
After conversion : {1, 2, 3}

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

247 Views