How to select and print a value from a list created by a "def"

1

The title is already self explanatory, how do I select and choose given str or int / float within a list that was created by my registry function

def registro(cadastroaluno):
    matricula = input("Número de Matrícula: ")
    telefone = input("Número de Telefone: ")
    endereco = input("Endereço: ")
    respReg = matricula,telefone,endereco
    return respReg

aluni = str
print(registro(aluni))

For example:

How do I select the value '32 ' on the line and print it shortly after?

    
asked by anonymous 23.02.2017 / 09:09

1 answer

1

What function returns is not a list, it's a tuple (think of it as an immutable list).

Your variable aluni , may no longer exist, this piece of code is no good at all.

As for your doubt because you do not do this:

def registro():
    matricula = input("Número de Matrícula: ")
    telefone = input("Número de Telefone: ")
    endereco = input("Endereço: ")
    return (matricula,telefone,endereco)

dados = registro() # dentro de dados tens todos os dados que foram introduzidos
print(dados[2])

Or you can do the unpacking of the tuple that returns to get the variables separately:

...
matricula, tele, endereco = registro()
print(endereco)

If you use only index 2 and delete the others, you can do it soon:

def registro():
    matricula = input("Número de Matrícula: ")
    telefone = input("Número de Telefone: ")
    endereco = input("Endereço: ")
    return (matricula,telefone,endereco)

endereco = registro()[2]
print(endereco)

Remember that the inputs always return strings, for the converters you can:

...
int(input("Endereço: "))
...
    
23.02.2017 / 09:42