About 19,400,000 results
Open links in new tab
  1. python - How do you create different variable names while in a loop

    Using dictionaries should be right way to keep the variables and associated values, and you may use this: dict_ = {} for i in range(9): dict_['string%s' % i] = 'Hello' But if you want to add the …

  2. python - Defining variables in a for loop - Stack Overflow

    Apr 3, 2015 · def add_var(self, variable, value): self.__dict__[variable] = value. an example with globals:

  3. How to Dynamically Declare Variables Inside a Loop in Python

    Jul 18, 2021 · I came up with three ways to do this in Python. 1. Using the exec command. In the above program, I initially declared an empty dictionary and added the elements into the …

  4. Using a loop in Python to name variables - Stack Overflow

    Nov 28, 2012 · How do I use a loop to name variables? For example, if I wanted to have a variable double_1 = 2, double_2 = 4 all the the way to double_12 = 24, how would I write it? I …

  5. Changing Variable Names With Python For Loops - GeeksforGeeks

    Feb 26, 2024 · In Python, the flexibility of for loops allows you to automate the process of changing variable names. In this article, we will explore various techniques to change variable …

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

  7. How to Use Multiple Variables in Python - Tutorial Reference

    Python's for loops are incredibly versatile. This guide explores how to effectively use multiple variables within for loops, covering techniques like tuple unpacking, iterating over dictionaries, …

  8. How to Use a for Loop for Multiple Variables in Python

    Feb 9, 2025 · To achieve multiple assignments within a dictionary using a for loop, the items() method is employed on the given Python dictionary. This provides the output as a list …

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

  10. Using multiple variables in a For loop in Python | bobbyhadz

    To use multiple variables in a for loop: Use the zip function to group multiple iterables into tuples. Use a for loop to iterate over the zip object. Unpack the items of each tuple into variables. The …

  11. Some results have been removed
Refresh