0

How can I print the variable name from a list instead of the value? I can iterate through the list and print the value below but I would like to know how to also iterate through the list and print the variable name?

a = 'Red'
b = 'Green'
c = 'Blue'

mylist = [a, b, c]
for i in mylist:
    print(i)

Current Output:

Red
Green
Blue

Desired Output:

a
b
c
MBasith
  • 1,407
  • 4
  • 29
  • 48

0 Answers0