Python Basics - Data Types Part 3 |

Published: 14 July 2026
on channel: AriCodes
21
3

Set Data Types: A Set is a built-in mutable and unordered data type used to store a collection of unique items.
Denoted by set, and initialized using {} i.e. curly braces, or set().
Used when you need to quickly strip out duplicate values from an existing list.

Two types of set data types:
1. set - mutable, unordered
2. frozenset - immutable, unordered

To create an empty set we use set(), if we use {} it will simply create an empty dictionary not an empty set.

Code:
numbers1 = {4, 2, 3, 1, 3, 2, 4, 2, 1, 3, 2, 3, 4, 3, 4, 1, 4, 2, 4, 3, 4}
print (numbers1)

numbers2 = set([4, 3, 2, 1, 2, 3, 4, 2, 3, 1, 2, 4, 3, 3, 4, 1, 4, 2, 4, 3, 4])
print (numbers2)

print(type(numbers1), type(numbers2))

numbers1.add(5)
print (numbers1)

numbers2.remove(4)
print (numbers2)

numbers3 = frozenset([1, 3, 2, 4, 2, 1, 3, 2, 3, 4, 3, 4, 1, 4, 2, 4, 3, 4])
print (numbers3)

numbers3.add(5)
print (numbers3)
will give error as 'frozenset' object has no attribute 'add'.


On this page of the site you can watch the video online Python Basics - Data Types Part 3 | with a duration of hours minute second in good quality, which was uploaded by the user AriCodes 14 July 2026, share the link with friends and acquaintances, this video has already been watched 21 times on youtube and it was liked by 3 viewers. Enjoy your viewing!