0

Suppose I have some arrays initialized named as hi, bi, ci. Like in Perl we have this curly braces {} for interpolating strings inside the name of variable names. How to do it in python?

hi_name = []
bi_name = []
ci_name = []

temp = ["hi", "bi", "ci"]

for i in temp:
  {i}_name.append("abc")  # How to accomplish this in Python

print hi, bi, ci

Or Is there any Other way I can do the above thing?

  • 1
    Possible duplicate of [How do I create a variable number of variables?](https://stackoverflow.com/questions/1373164/how-do-i-create-a-variable-number-of-variables) – glibdud Feb 12 '18 at 13:13
  • 2
    While possible, you don't want to do this. Better to make a dict called `name` that you can access with `name['hi']`, `name['bi']`, etc. – glibdud Feb 12 '18 at 13:14

0 Answers0