Python - How to print multiple variables in a loop?

Asked

Viewed 1,242 times

-1

I’m collecting 7 different values through a while. Every time the while wheel, a value is assigned to the variable valor and is printado, but would like to save each valor in a variable for later use.

For example, the first print, var1 = valor, the second time, var2 = valor, on the third time, var3 = valor...

  • First you need to decide whether to print or assign a value.

  • Stores read values in a list. You can set valor = [] and inside the while do: valor.append() to add the new value in the list, so each value will be stored in a different index and can be used later.

  • Hi Anderson, thanks for the help, it worked great! Would you like to tell me how to turn the string into an integer? Thanks in advance!

1 answer

1

If someone is in the same situation:

As Anderson Carlos Woss explained above, create a lista and use the lista.append(objeto) to put values in the list.

If you want to pass to a variable, set a variavel = lista[posição].

If your values are of the type string, and wish to transform into inteiro, when defining the variavel, do: variavel = int(lista[posição]).

Thank you to everyone who helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.