Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (120 points)
While having an iteration in looping, how can I use the comparison operator?

1 Answer

0 votes
by (119k points)
edited by

Here is the example of using a comparison operator in for loop:

#To find the maximum value of the list

number_List=[16,19,21,25,27,42]

largest_value = number_List[0]

for number in number_List:

        if number > largest_value:

                 largest_value=number

print(largest_value)

Explanation: Initialize the largest_value with the first element of the list. Go through each element of the list and check if that value is greater than the larget_value variable. If it is true update the largest_value with that number, otherwise go to the next iteration.

To learn Python programming, you can check out this Python Course by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Apr 16, 2021 in Java by sheela_singh (9.5k points)

Browse Categories

...