In this article, I'll explain about tuple, set and dictionary datatypes in Python
Tuple
Tuple
The tuple is exactly the same as list data type except that it is immutable, means we cannot change values once values are assigned.To
create a tuple, just list the values within parenthesis separated by commas.
Set
SET is an unordered collection of unique elements. It is used in membership testing, removing duplicates from a sequence, and computing mathematical operations such as intersection, union, difference, and symmetric difference.
Dictionary
SET is an unordered collection of unique elements. It is used in membership testing, removing duplicates from a sequence, and computing mathematical operations such as intersection, union, difference, and symmetric difference.
There are currently two types of sets
- Set
- Frozen Set
An example for Set
Frozen Set is immutable means we cannot change elements after assigning.
An example for Frozen Set
Mathematical operations on the set
- Union
- Intersection
- Difference
- Symmetric difference
Union
We can use this union() function to return all elements present in both sets.
Example for union()
Intersection
A set with all the elements which are contained in both sets is returned or Returns common elements present in both sets.
An example for intersection
Difference
Returns the elements present in set a but not in set b or difference()
method returns the set difference of both sets a and b.
An example for difference
Symmetric_Difference
Returns elements present in either set a or set b but not in both sets.
An example for Symmetric_difference
Dictionary
A
dictionary is a sequence of items. Each item contains a key and a
value. Dictionaries are not sorted.
An example for Dictionary
Thank you for taking the time to read my article.