[Python] How to print out variable name instead of value?

Discussão em 'Python' iniciado por Stack, Maio 7, 2025.

  1. Stack

    Stack Membro Participativo

    If I have a list of variables and each variable is assigned to an equation, how can I print the variable itself from the list not the result of the equation

    For example:

    x = 1 + 1
    y = 2 + 2
    z = 3 + 3

    list = [x, y, z]

    print(list[0])
    print(list[1])
    print(list[2])


    Should print out:

    x
    y
    z


    Instead of:

    2
    4
    6

    Continue reading...

Compartilhe esta Página