[Python] How to get parameter names inside python function

Discussão em 'Python' iniciado por Stack, Abril 25, 2025.

  1. Stack

    Stack Membro Participativo

    I've been working on it for a few days, but I can't tell. I need advice from Python masters. Thanks

    def myPrint(cmd=None):
    for name, value in globals().items():
    if value is cmd:
    print(f'{cmd} = {value}')

    a = 'alpha'
    b = 'alpha'
    myPrint(b)

    result>
    alpha = alpha
    alpha = alpha

    but I want to result...
    myPrint(a) ----> a = 'alpha'
    myPrint(b) ----> b = 'alpha'
    myPrint(a+b) ----> a+b = 'alphaalpha'

    Continue reading...

Compartilhe esta Página