0

In this case, I'm trying to create variable history0 using the value from accountno

accountno = 0
history<accountno> = 'dep 100$'
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Chol O
  • 17
  • 2
    Use lists or dictionaries, you do **not** want dynamic variable names. – luk2302 Mar 06 '22 at 08:26
  • This was my first major stumbling block when starting to work with Python. How do I create dynamic variable names for `var_A0, var_A1,..., var_An` containing values `val_A0, val_A1,...,val_An`? Answer: You don't. Store them in a list `list_A=[val_A0, val_A1,...val_An]` and retrieve the number of each value within the list with `for i, val_A in enumerate(list_A):`. Need to combine variables `var_A0,...,var_An` with their corresponding counterparts `var_B0,...,var_Bn`? Zip the two lists: `for val_A, val_B in zip(list_A, list_B):`. – Mr. T Mar 06 '22 at 08:41

0 Answers0