For example, we have the scores of three courses stored in LIST
.
English, Maths, Physics = 89, 92, 93
LIST = [English, Maths, Physics]
for i in range(len(LIST)):
print(LIST[i])
And I want the print style to be like English, 89
, Maths, 92
, Physics, 93
. Here is a solution that defines another list LIST_name
English, Maths, Physics = 89, 92, 93
LIST = [English, Maths, Physics]
LIST_name = ['English', 'Maths', 'Physics']
for i in range(len(LIST)):
print(LIST_name[i], LIST[i])
I am wondering if there is a built-in function or some other tricks that can help me directly convert English
to "English"
, without defining LIST_name
? And if so, how? As Barmar commented below, what I am looking for is how to go from a value to the name of the variable it came from?