1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Output the contents of a tuple in a print statement

Discussão em 'Python' iniciado por Stack, Setembro 12, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to print the contents of a tuple with a print statement like this:

    print("First value: %i, Next four values: %i %i %i %i, Next three values: %i %i %i\n" % (myTuple[0], myTuple[1], myTuple[2], myTuple[3], myTuple[4], myTuple[5], myTuple[6], myTuple[7]));


    Now as you can see in the example above the elements in a tuple are going to be output in order, but the format is such that you can't easily use a loop. Is there a way to just specify the whole tuple/list/set (or a given range) in print statement without specifying each element separately, something like this?

    print("First value: %i, Next four values: %i %i %i %i, Next three values: %i %i %i\n" % (myTuple[:7));

    Continue reading...

Compartilhe esta Página