About 3,790,000 results
Open links in new tab
  1. list - Python: for loop inside print () - Stack Overflow

    If you have to use a loop, do so in a list comprehension: print('The lists are:', '\n'.join([str(lst) for lst in L])) This'll omit the newline after 'The lists are:' , you can always use sep='\n' here as well.

  2. python - Can I include a for loop inside my print statement?

    Sep 11, 2016 · A for loop can only be supplied to print in the form of a comprehension. But, if the list contents are in the respective order you require you can simply do: print("The winners of {} …

  3. Is it possible to use for loops inside print statement in Python

    Feb 3, 2014 · You can use a generator expression: print(sum(i for i in range(1,1000) if i%3 == 0 or i%5 == 0)) Note that I'm using the built-in function sum() here, which is different than you …

  4. Python For Loops - W3Schools

    With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc. Print each fruit in a fruit list: The for loop does not require an indexing variable to set …

  5. Python For Loops - GeeksforGeeks

    Dec 10, 2024 · Python For Loops are used for iterating over a sequence like lists, tuples, strings, and ranges. For loop allows you to apply the same operation to every item within loop. Using …

  6. 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 …

  7. 7 Ways to Loop Through a List in Python - LearnPython.com

    Jul 29, 2022 · 7 Ways You Can Iterate Through a List in Python 1. A Simple for Loop. Using a Python for loop is one of the simplest methods for iterating over a list or any other sequence …

  8. Python For Loop - Syntax, Examples

    Python For Loop can be used to iterate a set of statements once for each item of a sequence or collection. The sequence or collection could be Range, List, Tuple, Dictionary, Set or a String. …

  9. Python for Loop (With Examples) - Programiz

    In Python, we use a for loop to iterate over sequences such as lists, strings, dictionaries, etc. For example, # access elements of the list one by one for lang in languages: print(lang) Output. In …

  10. Loops in Python with Examples

    When the inner loop is done, then the value of ‘i’ is incremented to check the condition on the outer loop and a new line is printed using the print(). Example of Python nested for loop: for i in …

Refresh