Skip to player
Skip to main content
Skip to footer
Search
Connect
Watch fullscreen
Like
Comments
Bookmark
Share
Add to Playlist
Report
Lecture 54: A Nested For Loop in Python
Nafees AI Lab
Follow
5/20/2025
A nested loop in Python refers to placing one loop inside another. The inner loop executes completely for each iteration of the outer loop. This structure is useful for tasks that require iterating over multiple dimensions or levels of data.
Category
📚
Learning
Transcript
Display full video transcript
00:00
In this lecture, we talk about nested for loop.
00:02
Nested for loop is not a basic fault.
00:05
For loop is called nested for loop.
00:08
For example, if I want to return the list1 item,
00:12
we have seen that for x is a variable.
00:15
This can be possible, this can be possible,
00:17
this can be possible, this can be possible,
00:19
this can be possible, this can be possible.
00:21
But I will put x in list1.
00:23
By the way, when I say anything,
00:25
this means that you have no idea
00:27
I mean, variable should be understandable.
00:32
But I am saying that this is a variable.
00:35
If I want to return the list1 item,
00:38
then I will print x.
00:41
And you see, 1, 2, 3.
00:43
If I want to return the list2 item,
00:47
then I will print y.
00:52
What if my requirement is that,
01:05
that I want to print all the elements of list2?
01:12
That is my requirement.
01:14
And I will give you a practical example.
01:17
But you can understand it.
01:19
For one, I want to print all the elements.
01:23
For two, I want to print all the elements.
01:25
For three, I want to nest two loops.
01:29
How can I nest two loops?
01:30
This is a very easy way.
01:32
Because I know that this block of code,
01:37
this block of code,
01:39
for first loop throughout this loop,
01:43
the block of code will be run.
01:45
and the elements will run?
01:46
And the elements will be run.
01:48
The two elements are in elements.
01:50
So three elements will try to print.
01:51
So three times run.
01:52
If this is run.
01:53
Therefore, the individual element will be run.
01:58
I will basically prepare
01:59
all the elements to be run.
02:01
From the list2 look模vel.
02:03
The two elements will run.
02:05
first, first, first element is equal to 1,
02:21
Now, I can use this value to this value, or discard this value and then I can use this value.
02:30
Let's say, how many times this is happening?
02:32
How many times this is happening?
02:33
2 plus 2.
02:35
And it will work.
02:37
With no problem.
02:38
I can understand this value.
02:41
Either you can use this value,
02:43
or you can run this value.
02:45
I can run this value.
02:47
I can run this value.
02:49
So, this value has been run.
02:51
With no problem.
02:52
This value run.
02:54
And the value is printed.
02:58
So, I can remove this value.
03:01
If I remove this value,
03:03
you can see the difference.
03:04
I can remove this value.
03:06
Sorry, I can remove this value.
03:09
So, this value is run.
03:11
Then I can remove this value.
03:13
Then I can use this value.
03:15
I can use.
03:16
So, how many times this value can be run this value?
03:18
So, I can use this value value.
03:20
Very good.
03:21
Excellent.
03:22
Now, I can use this value.
03:24
It's not so good to work.
03:25
So, I can use this value value for this value value.
03:26
So, I can run this value value.
03:28
For example, I can use this value value value value value.
03:30
I can run.
03:31
So, for x's first value, I want to work all the for loops for this list.
03:39
Now, if I go here and print the y's, let me leave the x.
03:46
Now, this is the 3rd value.
03:49
For the first value, the whole code is run.
03:53
For the second value, the whole code is run.
03:56
For the third value, the whole code is run.
03:59
And when I run, the whole code is run.
04:02
For the first value of x, it's a block of code is run.
04:05
And it's a new for loop.
04:07
For the first value of x, I will print both sides by side.
04:20
As you see, 1a, 1b, 1c.
04:24
And then it goes to 2.
04:26
Because when this loop is finished,
04:29
Then, this value of x's new value was passed.
04:34
And then, he asked us what to do.
04:36
He asked what to do.
04:37
He asked what to do.
04:38
He asked what to do.
04:39
He asked who?
04:40
It was 2.
04:41
Then, he asked what to do.
04:43
So, 2a, 2b, 2c.
04:44
Okay.
04:45
Good.
04:46
Good.
04:47
Good.
04:48
He asked what to do.
04:49
That value of x as if the parts have sat and knocked it.
04:51
Where all the values are are?
04:52
It said that 3.
04:53
It said that 3.
04:55
It's 3 top где.
04:57
And then, I asked, subpro
05:01
Basically, you can use two loops.
05:03
This is a practical application.
05:06
You have to generate two tables.
05:10
Generate table of two.
05:15
Two tables.
05:16
In school, there are 1-2-2-2-4.
05:19
If you go to English school,
05:22
I have to study English school.
05:25
Basically, 1-2-2-3.
05:28
And 2-2-2-4-2-4-2-4-2-3-6-4-8.
05:35
Let's generate table.
Recommended
11:19
|
Up next
Lecture 53: Python has for loop and Iterables
Nafees AI Lab
5/20/2025
7:14
Lecture 57: An Infinte Loop Function in Python
Nafees AI Lab
5/20/2025
6:23
Lecture 58: Python has keywords as Continue Break Pass
Nafees AI Lab
5/20/2025
7:54
Lecture 56: A Range Function in Python
Nafees AI Lab
5/20/2025
3:47
Loop Data , Loop Elements & Loop Break in Automa | Automa
Happy Automation
5/2/2024
3:41
Lecture 55: Learn to Generate a table of two in Python
Nafees AI Lab
5/22/2025
12:42
#20 Python Tutorial for Beginners //While Loop in Python
Top news
9/6/2022
7:27
#21 Python Tutorial for Beginners //For Loop in Python
Top news
9/6/2022
5:49
Lecture 60: Python has some functions
Nafees AI Lab
5/20/2025
4:03
Lecture 76: Python has Special Function Zip
Nafees AI Lab
5/23/2025
9:15
Lecture 45: Tuple Data Types in Python
Nafees AI Lab
5/18/2025
10:23
Lecture 78: List Comprehension in Python
Nafees AI Lab
5/23/2025
16:26
Loops Mix
Music - Movies - Games [Catan Channel]
9/10/2020
3:09
Fill Form with Loop on Data in Automa | Automa
Happy Automation
5/8/2024
6:49
Lecture 74: Python has Special Function Map
Nafees AI Lab
5/23/2025
0:27
Making waterproof shoes with duct tape! 👌🏞️
MetDaan Creative
4 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