[Python] Can we use python f-string placeholder with index number?

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

  1. Stack

    Stack Membro Participativo

    How can we achieve the following in Python 3.6 using f-string (instead of using format()) method?

    quantity = 3
    itemno = 567
    price = 49
    myorder = "I want {0} pieces of item number {1} for {2:.2f} dollars."
    print(myorder.format(quantity, itemno, price))


    Output:

    I want 3 pieces of item number 567 for 49.00 dollars.

    Continue reading...

Compartilhe esta Página