About 5,110,000 results
Open links in new tab
  1. Python- Finding the largest number in a list using forloop or …

    we can do this for both numbers and strings. A) Finding the largest number in a given list: # are larger numbers in the list. print("current number:", i) # Printing every item in the list . # regardless of their value. if i > largest_num: # Is it larger than -99999999?! largest_num = i # then value of largest number should be equal .

  2. How to find the maximum number in a list using a loop?

    If you want to use a loop, then loop with the current max value and check if each element is larger, and if so, assign to the current max. @TheodrosZelleke for i in range(len(list)): # for loop iterates through it. That's an explicit way of repeating something for the length of the list.

  3. Python Program to Find Largest Number in a List

    Oct 21, 2024 · Using a Loop (Native method) If we want to find the largest number in a list without using any built-in method (i.e. max ()) function then can use a loop (for loop).

  4. python - Find the greatest (largest, maximum) number in a list of ...

    Mar 8, 2023 · You can use the inbuilt function max() with multiple arguments: print max(1, 2, 3) or a list: list = [1, 2, 3] print max(list) or in fact anything iterable.

  5. Iterate over a list in Python - GeeksforGeeks

    Jan 2, 2025 · Python provides several ways to iterate over list. The simplest and the most common way to iterate over a list is to use a for loop. This method allows us to access each element in the list directly. Example: Print all elements in the list one by one using for loop. Let’s see other different ways to iterate over a list in Python.

  6. Python program to find N largest elements from a list

    May 17, 2023 · A for loop is used to iterate from 0 to n-1, and the first n elements of the sorted list are appended to the “res” list using the append () method. The sorted list is printed using the print () function and the “list1” variable.

  7. How to find the largest number in a list Python using for loop

    Dec 16, 2021 · Use temp variable and if statement to find the largest number in a list Python using for loop. Writing your own logic is easy, use temp variable to assign the first value of the list then swap it with the next large number.

  8. How To Find The Largest And Smallest Numbers In Python?

    Aug 29, 2024 · To find the largest and smallest number in a list in Python, you can use the built-in functions max() and min(). For example, if you have a list numbers = [3, 1, 4, 1, 5, 9, 2], you can find the largest number by calling max(numbers) and …

  9. How To Find Biggest Number In a List in Python

    Jul 6, 2023 · We will use for loop to find the biggest number, for example: max_num = num_list[0] for num in num_list: if num > max_num: max_num = num. print(max_num) Output: Explanation: In this example, we start by assuming that the first element of the …

  10. 5 Best Ways to Find the Number of Values Greater Than K in a Python List

    Mar 11, 2024 · Suppose we are given a list [1, 5, 8, 10, 7, 6, 3] and we want to find out how many elements are greater than the value k=6. The desired output for this example is 3, since there are three values (8, 10, and 7) that are greater than 6.

  11. Some results have been removed
Refresh