About 9,730,000 results
Open links in new tab
  1. For loop with custom steps in python - Stack Overflow

    reversed (range (len (list)) will not halve the w value. You can use a list comprehension in place of range (10). Or else, use a while loop!

  2. python - How do I loop through a list by twos? - Stack Overflow

    If you're using Python 2.6 or newer you can use the grouper recipe from the itertools module: from itertools import izip_longest def grouper(n, iterable, fillvalue=None): "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx" args = [iter(iterable)] * n return izip_longest(fillvalue=fillvalue, *args) Call like this: for item1, item2 in grouper(2, l):

  3. How can I use a for loop to iterate through numbered variables?

    Oct 15, 2015 · I've got 20 variables which are named line1, line2, line3, ..., up to line20. Is there a way in Python to use a for loop to reference each of these variables in sequence, i.e., iterate through them? Something to this effect: for i in range(1, 21): print(line + str(i)) Although I …

  4. Python - Loop Through a Range - GeeksforGeeks

    Dec 23, 2024 · In this article, we will explore the different ways to loop through a range in Python, demonstrating how we customize start, end, and step values, as well as alternative methods for more advanced use cases like looping through floating-point ranges or infinite sequences.

  5. Python For Loop Increment in Steps - Tutorial Kart

    To iterate through an iterable in steps, using for loop, you can use range () function. range () function allows to increment the "loop index" in required amount of steps.

  6. Python for Loops: The Pythonic Way – Real Python

    Python’s for loop iterates over items in a data collection, allowing you to execute code for each item. To iterate from 0 to 10, you use the for index in range(11): construct. To repeat code a number of times without processing the data of an iterable, use the …

  7. 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 beforehand. Even strings are iterable objects, they contain a sequence of characters: Loop through the letters in the word "banana":

  8. 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.

  9. Range with Steps - Python Examples

    Learn how to create a range in Python with a specified step value using the range () function. This tutorial covers the syntax and provides clear examples, demonstrating how to iterate through sequences with customizable step increments.

  10. Using range () in for Loops to Control Iterations in Python

    May 26, 2023 · The built-in Python range () function is an indispensable tool for controlling for loop iterations. By leveraging range (), you can iterate a precise number of times, skip iterations, reverse loops, and avoid off-by-one errors.

Refresh