a1 = 1
a2 = 2
a3 = 3
.......
a10000 = 10000
So, I want to create a function that will autoassign names to numbers. In the the code above,
for x in range (desired range):
a(quantity of x) = x
how do i get my code to call the quatity of x?
a1 = 1
a2 = 2
a3 = 3
.......
a10000 = 10000
So, I want to create a function that will autoassign names to numbers. In the the code above,
for x in range (desired range):
a(quantity of x) = x
how do i get my code to call the quatity of x?
Why not use a list? Or maybe a dictionary?
locals()['a' + str(x)] = x
What you have in mind is very poor programming!
Use a list or dictionary instead.
I need it for a code such as this:
row0 = ['3']
row1 = ['7', '4']
row2 = ['2', '4', '6']
row3 = ['8', '5', '9', '3']
for x in range(4):
nextNum = locals()['row' + str(x)]
I need it for a code such as this:
No that just stupid code.
Explain better what you want do,then you get suggestions for better ways to solve it.
Use
row = [
['3'],
['7', '4'],
['2', '4', '6'],
['8', '5', '9', '3'],
]
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.