Extract multiple values from a single variable in python

Asked

Viewed 722 times

2

If I have a single data input, I have to remove several values assigned to my variable and give to another?

representation:

vrvl = int(input("Dia.mês.ano: ))
dia = dia
mes = mes
ano = ano
#entrada == 22.08.17
print("Dia:", dia)
print("Mês:", mes)
print("Ano:", ano)

2 answers

3

Try to use split()

dia, mes, ano = input("Dia.mês.ano:").split('.')
print("Dia:", dia)
print("Mês:", mes)
print("Ano:", ano)

1

You could also use a list to store the information, something like that:

dia, mes, ano = input("Dia Mês Ano: ").split(' ')
lista = [dia, mes, ano]

It could facilitate the manipulation of this information depending on the objectives of your code.

Browser other questions tagged

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