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
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
Using a loop in Python to name variables - Stack Overflow
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 get the feeling it would be More on stackoverflow.com
🌐 stackoverflow.com
May 22, 2017
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
🌐
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 ...
🌐
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!

🌐
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...
🌐
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
🌐
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.

🌐
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.
🌐
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.
🌐
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”). ... ...
🌐
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.
🌐
Plain English
plainenglish.io › home › blog › python › how to dynamically declare variables inside a loop in python
How to Dynamically Declare Variables Inside a Loop in Python
July 18, 2021 - 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.