[Python] How to reduce verbosity of self-documenting expressions in Python f-strings?

Discussão em 'Python' iniciado por Stack, Fevereiro 6, 2025.

  1. Stack

    Stack Membro Participativo

    This script:

    import numpy as np

    a = np.array([2, 3, 1, 9], dtype='i4')
    print(a)
    print(f'{a=}')


    produces:

    [2 3 1 9]
    a=array([2, 3, 1, 9], dtype=int32)


    Is there a way to get just a=[2 3 1 9] from {a=} f-string as in the standard formatting in the first line?

    Continue reading...

Compartilhe esta Página