Sure you can; it's called a dictionary:

d = {}
for x in range(1, 10):
    d["string{0}".format(x)] = "Hello"
>>> d["string5"]
'Hello'
>>> d
{'string1': 'Hello',
 'string2': 'Hello',
 'string3': 'Hello',
 'string4': 'Hello',
 'string5': 'Hello',
 'string6': 'Hello',
 'string7': 'Hello',
 'string8': 'Hello',
 'string9': 'Hello'}

I said this somewhat tongue in check, but really the best way to associate one value with another value is a dictionary. That is what it was designed for!

Answer from the wolf on Stack Overflow
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-23500.html
Changing a variable's name on each iteration of a loop
Is it possible in python to change the name of a variable on each iteration of a loop? For example: for i in range(10): variableNameToChange+i='iterationNumber=='+str(i)I know this won't work, and you can't assign to an operator, but how would y...
Discussions

Is it possible to create variables in a loop?
You can create a dictionary or a list to save and easily access all these: # dictionary d = {} for i in range(1, 1000): d["var{0}".format(i)] = 0 # list var = [] for i in range(1, 1000): var.append(0) More on reddit.com
๐ŸŒ r/learnpython
5
2
June 10, 2022
Changing variable names with Python for loops - Stack Overflow
Release notes and bug fixes for beta.stackoverflow.com ... 0 Using python loop to change part of variable name within function (e.g. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Changing variable name in for loop?
The python-pptx library requires that I name each new slide something different How? A library shouldn't have access to the variable names you're creating. I looked at the docs but couldn't find anything. Can you provide an example? More on reddit.com
๐ŸŒ r/learnpython
5
2
May 2, 2022
Why does everyone teach FOR LOOPS with the same variable name?
What variable name would you use? More on reddit.com
๐ŸŒ r/learnpython
62
33
February 12, 2022
๐ŸŒ
Runestone Academy
runestone.academy โ€บ ns โ€บ books โ€บ published โ€บ foppff โ€บ more-about-iteration_naming-variables-in-for-loops.html
7.7 Naming Variables in For Loops
Use singular nouns for the iterator variable, which is also called the loop variable (things like โ€œsongโ€, โ€œbookโ€, โ€œpostโ€, โ€œletterโ€, โ€œwordโ€). ... Use plural nouns for the sequence variable (things like โ€œsongsโ€, โ€œbooksโ€, โ€œpostsโ€, โ€œlettersโ€, โ€œwordsโ€). ... ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ is it possible to create variables in a loop?
r/learnpython on Reddit: Is it possible to create variables in a loop?
June 10, 2022 -

I need to create a large number of variable. Currently what I have is:

var1 = 0
var2 = 0
...
var1000 = 0

Is it possible to create these variables in some sort of loop instead of writing each one?

#Pseudocode

for i in range(1000):
    var_i = 0

Update:

Thanks a lot for all the comments! The list idea worked!

๐ŸŒ
Runestone Academy
runestone.academy โ€บ ns โ€บ books โ€บ published โ€บ fopp โ€บ Iteration โ€บ WPNamingVariablesinForLoops.html
7.10. ๐Ÿ‘ฉโ€๐Ÿ’ป Naming Variables in For Loops โ€” Foundations of Python Programming
Use singular nouns for the iterator variable, which is also called the loop variable (things like โ€œsongโ€, โ€œbookโ€, โ€œpostโ€, โ€œletterโ€, โ€œwordโ€). Use plural nouns for the sequence variable (things like โ€œsongsโ€, โ€œbooksโ€, โ€œpostsโ€, โ€œlettersโ€, โ€œwordsโ€). While these ...
๐ŸŒ
Quora
quora.com โ€บ How-do-I-create-a-loop-that-creates-variables-in-Python
How to create a loop that creates variables in Python - Quora
6) When values are objects created in a loop, append them ... Use list: ordered sequence, numeric indices, iteration, slicing. Use dict: named keys, sparse or string names. Use object attributes: when attributes belong to a conceptual object. Avoid globals()/locals(): only for advanced metaprogramming or interactive sessions. Summary: Prefer lists, dicts, or objects over creating dynamic standalone variable names. They are clearer, safer, and idiomatic Python.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ changing-variable-names-with-python-for-loops
Changing Variable Names With Python For Loops - GeeksforGeeks
July 23, 2025 - In this example, below Python code below adds the prefix "var_" to each variable name in the list original_names. It uses a for loop to iterate through the original names, creates new names with the prefix, and appends them to the list prefixed_names.
Find elsewhere
๐ŸŒ
Quora
quora.com โ€บ How-can-I-change-the-name-of-a-variable-in-a-loop-in-Python
How to change the name of a variable in a loop in Python - Quora
Answer (1 of 13): Hello! I have a good and bad news for you. I start with the bad one. Producing a new variable name at each iteration of a for loop isnโ€™t a good idea. So I will give you a way to use Python `list` instead, to achieve the same thing. But now the good one: what you wanted to do a...
๐ŸŒ
Plain English
python.plainenglish.io โ€บ how-to-dynamically-declare-variables-inside-a-loop-in-python-21e6880aaf8a
How to Dynamically Declare Variables Inside a Loop in Python | by Naveenkumar M | Python in Plain English
August 9, 2024 - Then we name them x, y, and so on. The problem becomes more complicated when you need to declare variables dynamically in a loop. I came up with three ways to do this in Python. In the above program, I initially declared an empty dictionary and added the elements into the dictionary. I used string concatenation method to declare dynamic variables like x1, x2, x3โ€ฆโ€ฆ. . Then I assumed the values from the for ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ changing variable name in for loop?
r/learnpython on Reddit: Changing variable name in for loop?
May 2, 2022 -

Hello,

I know this is probably a really basic python task, but I have been unable to figure it out. I am using python-pptx to create a powerpoint. My actual script is more complex, but for the sake of this question, suppose I have a for loop with which I iterate on a list, and create a new slide for each item in the list. The python-pptx library requires that I name each new slide something different - how do I update the name of the variable for each loop iteration? In the example below, how would "slide1" become "slide2" as the loop progresses through the list?

list_of_slide_content = ["example","of","content"]
for cont in list_of_slide_content: 
    slide1 = pptx.slide(0)
    slide1.add_text(cont)
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ why does everyone teach for loops with the same variable name?
r/learnpython on Reddit: Why does everyone teach FOR LOOPS with the same variable name?
February 12, 2022 -

I'm trying to learn for loops but it feels like everyone teaches examples writing for loops with the same variable name but in the singular form.

Example:

For number in numbers:

For course in courses:

For plane in planes:

For car in cars:

Is there a reason why most people like writing their for loops this way. For me it takes a while to understand more than if they used a different variable name entirely.

๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ python dynamic variable name
Python Dynamic Variable Name | Delft Stack
December 14, 2023 - In this output, the dynamically created variable variable5 is printed, demonstrating how the for loop and globals() function can be utilized to generate dynamic variable names in Python.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Is it possible to write a loop that includes variables from a list? - Python Help - Discussions on Python.org
July 27, 2023 - Hi all, please bear with me as iโ€™m fairly new to Python. I have a working python script that does the following: Opens a csv file Edits the csv (removes first row, adds a column, data-fills column) Exports the csv with new name The source csv, new column name, and exported csv name are defined by variables.
๐ŸŒ
Quora
quora.com โ€บ How-do-you-create-different-variable-names-while-in-a-loop-in-Python
How to create different variable names while in a loop in Python - Quora
Avoid generating variable names in the global/local namespace unless absolutely necessary. ... Trying to create variables like var1, var2 inside loop and then using eval/exec โ€” fragile, slow, insecure. Late binding in closures (fix with default argument or factory). Use data structures; they are clearer, more maintainable, and idiomatic in Python.
๐ŸŒ
Librarycarpentry
librarycarpentry.github.io โ€บ lc-python-intro โ€บ 12-for-loops
For Loops โ€“ Python Intro for Libraries
May 8, 2023 - Update the variable with values from a collection. # Sum the first 10 integers. total = 0 for number in range(10): total = total + (number + 1) print(total) ... Add 1 to the current value of the loop variable number.
๐ŸŒ
Imperialcollegelondon
imperialcollegelondon.github.io โ€บ python-novice-mix โ€บ 07-for-loops โ€บ index.html
Programming in Python: For Loops
November 8, 2018 - The loop variable, number, is what changes for each iteration of the loop. The โ€œcurrent thingโ€. ... Created on demand. Meaningless: their names can be anything at all.