About 5,000,000 results
Open links in new tab
  1. Why does python use 'else' after for and while loops?

    Feb 13, 2016 · Almost 10 years after this question has been asked and after programming with Python for 3 years, this is the first time I've seen the "for-else", "while-else" construct. I hope its low …

  2. python - How can I break out of multiple loops? - Stack Overflow

    68 I tend to agree that refactoring into a function is usually the best approach for this sort of situation, but for when you really need to break out of nested loops, here's an interesting variant of the exception …

  3. python - How can I access the index value in a 'for' loop? - Stack …

    167 Tested on Python 3.12 Here are twelve examples of how you can access the indices with their corresponding array's elements using for loops, while loops and some looping functions. Note that …

  4. for loop in Python - Stack Overflow

    60 You should also know that in Python, iterating over integer indices is bad style, and also slower than the alternative. If you just want to look at each of the items in a list or dict, loop directly through the …

  5. python - Why do we use "i" in loops such as in "for i in range ...

    Feb 4, 2018 · 2 Why is "i" often used in learning materials when illustrating loops? For example, it's used when looping over a range function. Using a random number just seems more logical to me since the …

  6. Delay between for loop iteration (python) - Stack Overflow

    11 Is this possible in Python? I wrote a great loop/script in Python and I’d like to add this delay to it if at all possible.

  7. python - Iterating over a dictionary using a 'for' loop, getting keys ...

    Mar 16, 2017 · This is how Python knows to exit a for loop, or a list comprehension, or a generator expression, or any other iterative context. Once an iterator raises StopIteration it will always raise it - …

  8. python - Get loop count inside a for-loop - Stack Overflow

    This for loop iterates over all elements in a list: for item in my_list: print item Is there a way to know within the loop how many times I've been looping so far? For instance, I want to take a

  9. python - Nested For Loops Using List Comprehension - Stack Overflow

    Sep 3, 2010 · Nested For Loops Using List Comprehension [duplicate] Asked 15 years, 3 months ago Modified 3 years, 9 months ago Viewed 122k times

  10. Are infinite for loops possible in Python? - Stack Overflow

    Is it possible to get an infinite loop in for loop? My guess is that there can be an infinite for loop in Python. I'd like to know this for future references.