Python set() FunctionPython Functions

Difficulty Level:
Difficulty Level:

The set() function creates a set object which will appear in random order.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-


x = set('ABCDE')
print(x)

x = set('AAAABCDE')   # Duplicate items will be deleted
print(x)

x = set('AAABBBCCCDDDEEE') # Duplicate items will be deleted
print(x)

Output:

{'E', 'D', 'B', 'A', 'C'}
{'E', 'D', 'B', 'A', 'C'}
{'E', 'D', 'B', 'A', 'C'}

Syntax

set(obejct)

Parameters

Name Description
object A sequence, collection, or an iterator object.

Return Value

It returns a set object.

Advertisement

© 2021 Pythonexample.org, all rights reserved. Privacy Policy | Contact Us