0
list1=1
list2=10
list3=100
for i in range (1,4):
  print(listi)

For example, I have 3 lists where their names are the same for the list but different from i. How can I print list(i) in a simple way?

BigBO
  • 121
  • 1
  • 7
  • 2
    This is usually a bad idea. Create a real list instead. – Michael Butscher Jan 14 '23 at 16:52
  • A more direct albeit non Pythonic way is to use the `locals()` dictionary which already contains the variables available in scope. So in your case you need to print `locals()[f'list{i}']` . Same thing can happen for global variables using the built-in `globals()` dictionary – Nikos Athanasiou Jan 14 '23 at 17:04

0 Answers0