Linked Questions
1,494 questions linked to/from How do I create variable variables?
210
votes
9
answers
699k
views
How do you create different variable names while in a loop? [duplicate]
For example purposes...
for x in range(0,9):
string'x' = "Hello"
So I end up with string1, string2, string3... all equaling "Hello"
233
votes
8
answers
626k
views
How can you dynamically create variables? [duplicate]
I want to create variables dynamically in Python. Does anyone have any creative means of doing this?
186
votes
3
answers
512k
views
Using a string variable as a variable name [duplicate]
I have a variable with a string assigned to it and I want to define a new variable based on that string.
foo = "bar"
foo = "something else"
# What I actually want is:
bar = &...
48
votes
8
answers
110k
views
How can I make multiple empty lists in Python? [duplicate]
How can I make many empty lists without manually typing the following?
list1=[], list2=[], list3=[]
Is there a for loop that will make me 'n' number of such empty lists?
122
votes
7
answers
105k
views
Dynamically set local variable [duplicate]
How do you dynamically set local variable in Python (where the variable name is dynamic)?
78
votes
6
answers
145k
views
generating variable names on fly in python [duplicate]
Is there a way I can generate variable names in python in a loop and assign values to them? For example, if I have
prices = [5, 12, 45]
I want
price1 = 5
price2 = 12
price3 = 45
Can I do this in a ...
39
votes
7
answers
168k
views
How to assign each element of a list to a separate variable? [duplicate]
if I have a list, say:
ll = ['xx','yy','zz']
and I want to assign each element of this list to a separate variable:
var1 = xx
var2 = yy
var3 = zz
without knowing how long the list is, how would I do ...
45
votes
3
answers
172k
views
How can I concat multiple dataframes in Python? [duplicate]
I have multiple (more than 100) dataframes. How can I concat all of them?
The problem is, that I have too many dataframes, that I can not write them manually in a list, like this:
>>> ...
41
votes
5
answers
227k
views
Changing variable names with Python for loops [duplicate]
I was just wondering if anyone knew of a way to change variable names based off of a for loop for something like this:
for i in range(3)
group+i=self.getGroup(selected, header+i)
so that the ...
22
votes
5
answers
97k
views
Using a loop in Python to name variables [duplicate]
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 ...
15
votes
5
answers
38k
views
Assign split values to multiple variables [duplicate]
I am currently writing a Python script to handle some logs and reformat certain parts. Part of the script makes use of the following code (as an example):
var1,var2,var3=foo.split("|")
...
19
votes
7
answers
47k
views
Assign multiple variables at once with dynamic variable names [duplicate]
I'm aware I can assign multiple variables to multiple values at once with:
(foo, bar, baz) = 1, 2, 3
And have foo = 1, bar = 2, and so on.
But how could I make the names of the variables more ...
16
votes
4
answers
85k
views
How to increment variable names/Is this a bad idea [duplicate]
In Python, if I were to have a user input the number X, and then the program enters a for loop in which the user inputs X values, is there a way/is it a bad idea to have variable names automatically ...
10
votes
6
answers
75k
views
How to create multiple lists? [duplicate]
I'm trying to create multiple lists like the following:
l1 = []
l2 = []
..
ln = []
Is there any way to do that?
8
votes
2
answers
95k
views
Python List as variable name [duplicate]
I've been playing with Python and I have this list that I need worked out. Basically I type a list of games into the multidimensional array and then for each one, it will make 3 variables based on ...