Python 3 Program to Find the Largest Number in the Array or List of Numbers Tutorial For Beginners
798 views
Jun 1, 2025
Get the full source code of application here:
View Video Transcript
0:00
uh hello guys welcome to this video so
0:02
in this video I will show you a very
0:04
simple program inside Python which is
0:07
typically asked inside interviews and
0:09
competitive programming how to get the
0:11
largest number from a
0:14
list array of list of numbers so if you
0:17
have a bunch of numbers inside this list
0:19
something like we have this inside the
0:22
program 12 45 67 23 89 5 so quite a
0:29
number of ways by which you can do this
0:31
i will show the very simplest way using
0:33
the for
0:35
loop so now let me first of all execute
0:37
this program and show the output how it
0:40
executes so as soon as you execute this
0:43
it will calculate all the numbers which
0:45
are present right here and the output
0:48
should be 67 as you can see it is the
0:50
largest
0:52
number so it will result the largest
0:55
number in the list is 89 sorry the
0:58
largest number is
1:01
89 so it basically finds out the largest
1:05
number and returns it so now let me show
1:07
you how it
1:09
does for this let me show you uh this
1:13
software which is Python tutor which is
1:15
a very famous tool for explaining
1:17
programs so I will show you visualize it
1:20
step by step so first of all we have the
1:23
bunch of numbers right here in this
1:26
array list of numbers so it registered
1:29
right here so which zero index it is 12
1:33
45 67 23 89 5 so now I'll be showing you
1:38
the very easiest way by which we'll be
1:40
using the for loop and we will go one by
1:44
one to each
1:45
number and uh do the calculation for
1:49
this we will declare a variable which
1:51
will be holding the maximum
1:54
number this variable name can be
1:56
anything i'm just calling it maximum
1:59
number and I'm initializing it to the
2:02
first number in the array which is 12 by
2:06
default so we are assuming that first
2:09
number is the largest number so we are
2:11
storing it number zero so we are
2:14
accessing the first element in the array
2:16
which is 12 so as you can see maximum
2:19
number is 12 so now we are simply having
2:24
this for loop we are looping through
2:26
this array so now inside this array
2:30
sorry for loop we have this if condition
2:32
that if the number is greater than the
2:34
maximum number then we are simply
2:37
initializing that number to the maximum
2:39
number so we are updating it so now the
2:42
first array first number is 12 so 12 is
2:45
not greater than 12 so this condition
2:49
will evaluate to false so this will not
2:51
be executed so as you can see the number
2:54
is 12 the maximum number is also 12 so
2:57
this condition will not be executed we
2:59
come to the next number which is 45 so
3:02
in this case 45 is greater than 12 so
3:07
now we will be replacing this 12 number
3:10
with 45
3:12
so this will
3:14
do so now we will initialize this update
3:18
this maximum number
3:20
variable so as you can see now it has
3:23
changed from 12 to 45 now we will come
3:26
to the next number in the list which is
3:28
67 so 67 is greater
3:33
than 45 so this again
3:37
will update and once again this number
3:40
will be replaced now 67 will be replaced
3:44
here as you can see now we'll be coming
3:47
to the next number which is 23 so this
3:50
condition will evaluates to false
3:52
because 23 is not greater than 67 so we
3:56
will move to the next
3:58
number which is 89 so once again 89 is
4:02
the largest number so 89 is greater than
4:05
67 so this if condition will evaluates
4:09
to true so 67 will be replaced by
4:13
89 so you can just see how easy it is
4:17
now you'll come to the next number which
4:19
is five which is not the largest number
4:23
you'll be moving to the next index so
4:26
now this will the for loop will break
4:28
out and then we'll simply print out the
4:32
largest number of the list is
4:35
89 so this is a very simplest approach
4:39
guys using the for loop we require only
4:42
one variable for this approach which is
4:44
maximum number where you will store the
4:48
maximum number while looping through the
4:50
list we are processing each number in
4:52
the list and simply comparing that if
4:54
the number is greater than that if it is
4:57
greater then we are replacing it and
4:59
after that finding out each processing
5:02
each element then we are returning the
5:04
largest number in the list so very
5:06
simple simple uh approach and it
5:10
actually takes very few steps as well so
5:14
thank you very much for watching this
5:16
video and also check out my website
5:18
freemediatools.com
5:20
uh which contains thousands of tools