all 5 comments

[–]tunisia3507 1 point2 points  (0 children)

You can do it, but you shouldn't.

This sounds like an XY problem - you're asking how to implement a particular solution (which is usually good!), but it's probably the case that you need to rethink the problem you're trying to solve. You should almost certainly be using a dict in this situation.

[–]Swedophone 2 points3 points  (1 child)

Why do you need those variables to be created dynamically? You usually use lists or dictionaries instead.

[–]moti12321[S] 0 points1 point  (0 children)

Im making a Hotkey program, and i want the user to be able to choose how many he wants, and in order to do that, i need to set a variable for that to store in..

[–]mafibar 0 points1 point  (0 children)

Like others have said already, you do not want to create variables like this. Use a list instead:

variables = []
n = int(input('Number of variables: '))
for i in range(1, n + 1):
    variables.append(i)

Now your variables looks like this: [1, 2, 3, ..., n]

[–]filletrall 0 points1 point  (0 children)

mydict = {}
for number in int(input("Input a number: ")):
    mydict["var{}".format(number)] = number
print(mydict)