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

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
Changing a variable name in a for loop?

"I want to define several variables with trailing ascending numbers 0, 1, 2, etc." is a red flag that you really should be using a list.

More on reddit.com
🌐 r/Python
8
0
June 15, 2016
🌐
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 › 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”). ... ...
🌐
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 ...
🌐
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.
🌐
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...
Find elsewhere
🌐
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.

🌐
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
Answer (1 of 6): You don’t. Now I know someone will come along with a solution involving locals(), but then to use those ‘variables’ in your code you would need use ‘locals()’. Misusing locals() especially writing to it is a sign of a bad design. It is far simpler just to add items ...
🌐
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 ...
🌐
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.
🌐
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.
🌐
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.