-3

I need to change an int value by strings combination

x = 'person'
y = '400'

person400 = 1000

eval(x + y) = 3000 #i want to change person400 value by strings combination 


print(person400) # print 3000
TheGoldenTree
  • 158
  • 4
  • 16
Jonh
  • 3
  • 1

1 Answers1

-1

eval only evaluates the value of an expression. So if you want to execute a line of code you need to use exec.

Also the whole assignment needs to be inside exec, so that everything gets run as one line of code.
exec(x + y + '= 3000').
Which in your example will run as exec('person400 = 3000').

However this is a really bad way of setting variables so make sure you think it makes sense.

rosaqq
  • 426
  • 4
  • 16