About 50 results
Open links in new tab
  1. Understanding for loops in Python - Stack Overflow

    In simple terms, Python loops over an iterable object, such as a string, list or tuple. For a list, it will loop through the list elements:

  2. How can I make sense of the `else` clause of Python loops?

    Jun 5, 2016 · Many Python programmers are probably unaware that the syntax of while loops and for loops includes an optional else: clause: for val in iterable: do_something(val) else: clean_up() The bod...

  3. loops - When to use "while" or "for" in Python - Stack Overflow

    Dec 27, 2022 · For loops are used when you want to do operations on each member of a sequence, in order. While loops are used when you need to: operate on the elements out-of-order, access / …

  4. How to make a for-loop more understandable in python?

    May 8, 2019 · 1 Python for loops operate differently from traditional C style for loops as explained here. They function more like "for each" loops found in other languages or an iterator method. The range …

  5. Why does python use 'else' after for and while loops?

    Feb 13, 2016 · Loops follow a path until the "goal" is completed. The issue is that else is a word that clearly define the last option in a condition. The semantics of the word are both shared by Python …

  6. python - Single Line Nested For Loops - Stack Overflow

    Feb 25, 2015 · The best source of information is the official Python tutorial on list comprehensions. List comprehensions are nearly the same as for loops (certainly any list comprehension can be written as …

  7. python - Breaking out of nested loops - Stack Overflow

    Mar 17, 2009 · 3 In this particular case, you can merge the loops with a modern python (3.0 and probably 2.6, too) by using itertools.product. I for myself took this as a rule of thumb, if you nest too …

  8. Why Python is so slow for a simple for loop? - Stack Overflow

    Python is a really crappy language to implement tight inner loops in. The default (and for the time being most popular and widely-supported) implementation is a simple bytecode interpreter.

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

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

  10. python - How do you create different variable names while in a loop ...

    It's simply pointless to create variable variable names. Why? They are unnecessary: You can store everything in lists, dictionarys and so on They are hard to create: You have to use exec or globals() …