Skip to player
Skip to main content
Skip to footer
Search
Connect
Watch fullscreen
Like
Comments
Bookmark
Share
Add to Playlist
Report
Lecture 46: Set Data Types in Python
Nafees AI Lab
Follow
5/18/2025
In Python, a set is a built-in data type used to store an unordered collection of unique elements. Sets are mutable, meaning elements can be added or removed after the set is created. Python also offers frozenset, an immutable version of a set.
Category
📚
Learning
Transcript
Display full video transcript
00:00
Welcome back and good morning.
00:30
Welcome back and good morning.
01:00
Congratulations.
01:01
आपने पहला जो टेस्ट से जो सेट है वो डिफाइन कर लिया.
01:05
अब पहली डेफिनेशन यह थी कि यह अन ओर्डर होता है.
01:08
इसका मतलब यह है कि अगर मैं इसको कहूं कि यार मुझे जिरोत इंडेक्स के उपर बताओ कौन सा एलिमेंट फड़ा हुआ है.
01:14
पढ़ा हुआ है तो यह मुझे एरर देगा कहेगा यह और्डर नहीं है.
01:18
आप ऐसे एकसेस नहीं कर सकते है अलिमेंट को.
01:21
दूसरी चीज इसकी मैंने यह कही थी कि यह यूनिक आपजेक्ट को ओल्ड करता है.
01:25
मतलब यह है कि अगर इसके अंदर मैं एक और फाइव ऐलिमेंट डाल दूँ और इसको प्रिंट कराऊं तो लेट सी अगर हमार पास क्या आता है.
01:32
तो क्योंके दो दफाफा फाइव आया यूनिक नहीं रहा तो उसने का नहीं मैं दूसरे डिसकार्ड करने लगा हूं मैं सिर्फ एक फाइव को ओल्ड करूंगा.
01:40
This way you will see that you will only have one, two, three, four and five. Nothing else.
01:52
This is unique objects.
01:54
Okay.
01:56
Let's talk about built-in methods.
02:01
First of all, add method.
02:03
For example, if I test set, underscore set, dot add method call,
02:08
and I will say that I will add 100.
02:11
If I print it, I will add test set.
02:17
I will cut and run.
02:21
Now we will see that our previous set was 5,
02:24
and this value return.
02:27
This method itself is a new method return.
02:33
This method will add a new copy value.
02:38
For example,
02:41
new, underscore set, is equal to test, test, underscore set, dot copy.
02:50
So, dot copy basically,
02:52
is a method which we call the test set,
02:54
which we call the new set.
02:56
Okay.
02:57
Now, in the new set,
02:58
we can call the simple dot add method.
03:02
However, again,
03:04
because the value value is not returned,
03:07
the original value is in change.
03:09
So, we will show the value value to the original value.
03:13
For example,
03:15
I will disengage the copy and test set,
03:18
because the change was in change.
03:19
So, now I will add the test set.
03:21
I will print the test set.
03:22
I will print it.
03:23
I will print it.
03:24
I will print it.
03:26
And run it.
03:27
You will see that 100 value will be returned.
03:30
I will remove it.
03:32
Okay.
03:34
Because 100 already exists,
03:36
it will be added.
03:38
Let's see if I can add 5.
03:40
Run it.
03:41
The 5 cannot be added.
03:42
As you can see.
03:43
Okay.
03:44
Okay.
03:45
Okay.
03:46
Okay.
03:47
Now,
03:48
let's see.
03:49
Let's see.
03:50
Let's see.
03:51
Set theory.
03:52
Set theory.
03:53
For example,
03:54
if you have a set A,
03:56
and this set B,
03:57
what can you do?
03:59
What can you do?
04:00
Union can do something like that.
04:02
Something like that.
04:03
Okay.
04:04
And two sets can do intersection.
04:06
Okay.
04:07
And two sets can do difference.
04:10
Let's see.
04:11
Let's see.
04:12
Let's see.
04:13
Let's see.
04:14
One, two, three.
04:15
Just for the sake of simplicity.
04:17
So,
04:18
we have a test set.
04:19
Let's see.
04:20
Union.
04:21
You can see.
04:22
Union.
04:23
You can see.
04:24
This is a test set.
04:25
And one.
04:26
We have a test set.
04:27
And two.
04:28
Use.
04:29
Let's see.
04:30
And one.
04:31
Two.
04:32
Three.
04:33
Just for the sake of simplicity.
04:35
So,
04:36
two.
04:37
We have a test set.
04:38
First,
04:39
we can see.
04:40
Test.
04:41
Underscore.
04:42
Set.
04:43
1.
04:44
Union.
04:45
Union.
04:46
Union.
04:47
With test set.
04:48
2.
04:49
Union.
04:50
There is a set set.
04:51
But,
04:52
the common element is redundant.
04:53
It is not redundant.
04:54
It is not repeated.
04:55
For example,
04:56
I say,
04:57
No.
04:58
Just for the sake of simplicity.
05:00
Just for the sake of simplicity.
05:01
So,
05:02
we have a test set.
05:03
We have a test set.
05:04
I say,
05:05
Nine.
05:06
Nine.
05:07
Nine.
05:08
Nine.
05:09
Nine.
05:10
Nine.
05:11
Nine.
05:12
Nine.
05:13
Nine.
05:14
Nine.
05:15
Nine.
05:16
Nine.
05:17
Nine.
05:18
Nine.
05:19
Nine.
05:20
Nine.
05:21
Nine.
05:22
Nine.
05:23
Nine.
05:24
Nine.
05:25
Nine.
05:26
Nine.
05:27
Nine.
05:28
Nine.
05:29
Nine.
05:30
Nine.
05:31
Nine.
05:32
Nine.
05:33
Nine.
05:34
you see the same result union
05:41
this is intersection
05:44
union is just join
05:48
intersection will return
05:51
which are common
05:53
intersection
05:55
test one test two
05:57
as you see
06:00
common
06:02
nine
06:04
let's say
06:05
seven
06:06
seven
06:07
common
06:08
now
06:09
you will be
06:10
common
06:11
nine
06:12
and seven
06:13
basically
06:14
if I go back
06:16
diagram
06:17
this intersection
06:20
this region
06:22
return
06:23
this set
06:24
a
06:25
this
06:26
common values
06:27
return
06:28
however
06:29
union
06:30
two set
06:32
union
06:33
then
06:35
this area
06:36
return
06:37
this
06:38
area
06:39
return
06:40
intersection
06:41
uniquely
06:42
return
06:43
as a single region
06:45
return
06:46
you understand
06:47
intersection
06:48
is
06:49
this
06:50
line
06:51
uniquely
06:52
set
06:53
return
06:54
this
06:55
is
06:56
difference
06:57
difference
06:58
basically
06:59
you can see
07:01
intersection
07:02
you can see
07:03
one
07:04
two
07:05
three
07:06
and
07:07
eight
07:08
you can see
07:09
you can see
07:10
one
07:11
two
07:12
three
07:13
one
07:14
two
07:15
three
07:16
and
07:17
eight
07:18
so
07:19
you can see
07:20
one
07:21
two
07:22
three
07:23
eight
07:24
basically
07:25
set
07:26
one
07:27
two
07:28
eight
07:29
basically
07:30
set
07:31
one
07:32
exist
07:33
set
07:34
one
07:35
set
07:36
two
07:37
order
07:38
that is
07:39
very important
07:40
for example
07:41
if you
07:42
intersection
07:43
with
07:44
set
07:45
two
07:46
and set
07:47
one
07:48
result
07:49
will be
07:50
different
07:51
so
07:52
you can see
07:53
union
07:54
difference
07:55
because
07:56
if
07:57
one
07:58
result
07:59
will be
08:00
different
08:01
as you
08:02
see
08:03
one
08:04
two
08:05
three
08:06
okay
08:07
so
08:08
congratulations
08:09
guys
08:10
you have
08:11
done
08:12
the data
08:13
structure
08:14
completely
08:15
give
08:16
yourself
08:17
a big
08:18
tap
08:19
okay
08:20
close
08:21
and then
08:22
we will
08:23
start
Recommended
9:15
|
Up next
Lecture 45: Tuple Data Types in Python
Nafees AI Lab
5/18/2025
8:19
Lecture 36: Python has Data Structor and Lists
Nafees AI Lab
5/17/2025
9:59
Lecture 37: Python has Data Structor and Lists-II
Nafees AI Lab
5/17/2025
11:19
Lecture 53: Python has for loop and Iterables
Nafees AI Lab
5/20/2025
3:41
Lecture 32: Python is Immutable
Nafees AI Lab
5/16/2025
5:10
Lecture 43: Python has Un-changeable dic key
Nafees AI Lab
5/18/2025
8:48
Lecture 42: Dictionary in Python Language
Nafees AI Lab
5/18/2025
3:23
Lecture 79: Sets and Dictionary Comprehension in Python
Nafees AI Lab
5/23/2025
0:27
Making waterproof shoes with duct tape! 👌🏞️
MetDaan Creative
5 days ago
0:16
When it's your boyfriend's laundry day! 😅🤣
MetDaan Creative
5 days ago
0:24
Spreading chocolate cream with a plaster! 😅🍞
MetDaan Creative
5 days ago
7:40
Mera Mazloom Hussain | Nadeem Sarwar 2020 | 1442
Gham-e-Hussain | غمِ حسینؑ
6/9/2025
9:38
Episode 1 – The Curious Boy from Ulm (1879-1895)
Nafees AI Lab
6/8/2025
0:37
Top Fully Funded Scholarships in Germany 2025 🇩🇪 | Apply Now!
Nafees AI Lab
6/3/2025
0:25
The Boy and the Dragon – “A Friend in the Sky”
Nafees AI Lab
6/3/2025
1:03
Why Do Rainbows Appear? 🌈 | Physics in Everyday Life
Nafees AI Lab
6/3/2025
0:28
Albert Einstein: The Genius Who Changed Time
Nafees AI Lab
6/1/2025
0:40
Stephen Hawking’s Life in 60 Seconds: From Wheelchair to the Universe
Nafees AI Lab
6/1/2025
0:36
The Forgotten Night Hitler Was Nearly Killed
Nafees AI Lab
5/29/2025
0:31
Dilip Kumar – The Tragedy King of Bollywood
Nafees AI Lab
5/29/2025
0:45
Marlon Brando – The Rebel Who Redefined Acting | Nafees AI Lab
Nafees AI Lab
5/29/2025
0:29
Charles Darwin – Evolution & Natural Selection | Nafees AI Lab
Nafees AI Lab
5/28/2025
0:30
Isaac Newton – Gravity, Motion & Genius | Nafees AI Lab
Nafees AI Lab
5/28/2025
0:52
Allama Iqbal – Poet of the East | Nafees AI Lab
Nafees AI Lab
5/28/2025
0:53
Marie Curie – Life & Achievements | Nafees AI Lab
Nafees AI Lab
5/28/2025