About 2,830,000 results
Open links in new tab
  1. Initialize variable in for loop in Python? - Stack Overflow

    Jun 5, 2020 · You can use reduce and lambda: import functools functools.reduce(lambda x, y: x + y, range(10)) Check out: https://docs.python.org/3/library/functools.html#functools.reduce

  2. python - What's the pythonic way of conditional variable initialization ...

    Dec 6, 2011 · Since conditionals do not introduce new scope, constructs in other languages (such as initializing a variable before that condition) aren't necessarily needed. For example, we …

  3. Creating variables in loop and initialize them in Python

    Oct 31, 2014 · You can use locals() and globals() to dynamically assign variables. >>> param = range(10) >>> var = 'abcdefghij' >>> locals().update({'{}_true'.format(k): v for k, v in zip(var, …

  4. Why don't we have to initialize the variable of a for loop? - Python

    Jul 28, 2018 · In Python, a for loop variable does not have to be initialized beforehand. This is because of how Python for loops work. When it runs, the for loop statement will initialize the …

  5. Python For Loops - W3Schools

    Python For Loops. A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string). This is less like the for keyword in other programming languages, …

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

    Python’s for loop allows you to iterate over the items in a collection, such as lists, tuples, strings, and dictionaries. The for loop syntax declares a loop variable that takes each item from the …

  7. Python For loop and if else Exercises [22 Exercise Programs]

    Apr 19, 2025 · This Python loop exercise contains 22 different coding questions, programs, and challenges to solve using if-else conditions, for loops, the range() function, and while loops. …

  8. Python For Loop – Example and Tutorial - freeCodeCamp.org

    Jul 27, 2021 · Specifically, a for loop lets you execute a block of similar code operations, over and over again, until a condition is met. You repeat certain code instructions for a set of values you …

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

  10. python - Add Looped Variable Values - Stack Overflow

    Jun 2, 2022 · Initialize a variable that will be used in the test condition: What will be tested to determine if the loop is executed or not? Write a line of code that initializes a variable to be …

  11. Some results have been removed
Refresh