A set is an unordered
collection with no duplicate elements. Basic uses include membership testing
and eliminating duplicate entries.
Set objects also support mathematical operations like union, intersection, difference, and symmetric difference. Curly braces or the set() function can be used to create sets. Note: to create an empty set you have to use set(), not {}; the latter creates an empty dictionary, a data structure that we will discuss further.
Set objects also support mathematical operations like union, intersection, difference, and symmetric difference. Curly braces or the set() function can be used to create sets. Note: to create an empty set you have to use set(), not {}; the latter creates an empty dictionary, a data structure that we will discuss further.
The best way to learn new things is to take a practical approach of the things you want to learn. Here is a fragment of code that demonstrates the use of the Set statement in Python:
Æ’ python command
brands = ['Tesla', 'Porsche', 'Ford',
'BMW', 'Audi']
cars = set(brands)
print('Tesla' in cars)
print('Mercedes' in cars)
√ output
True
False
Sign up here with your email
ConversionConversion EmoticonEmoticon