-1

In Python I want to assign values to certain variables by putting them first in a list and assigning them values by indexing. For example:

I want to assign x = 1, y = 2, z = 3.

Rather than coding it one by one, I want to assign the variables as follows:

list_variables = [x, y, z]

list_values = [1, 2, 3]

for i in range(0, 3):

 list_variables[i] = list_values[i]

However it does not work. This type of assigning would really make my life easier because I am having hard time loading saved data to my variables by the pickle.load method. Thank you.

MisterMiyagi
  • 44,374
  • 10
  • 104
  • 119

1 Answers1

0

you just need to put variable names on LHS and the value list on RHS

x,y,x = value_list

this will automatically spread the values to the variables

Rohit Patil
  • 162
  • 8