Problem using function . Join()

Asked

Viewed 311 times

1

What’s wrong with this code of mine, I used the function. split() to separate the string when it finds ' ; ' after separating I wanted to join back by placing spaces so I used the . Join(), but saw no effects see:

#Irá separar cada palavra quando encontrar o delimitador ';'

reg = str(input('Nome; endereço; telefone: '))

nome, endereco, telefone = reg.split(';')
print('{}  {}  {} '.format(nome, endereco, telefone))

' '.join(reg)
print(reg)

'''
Tentei fazer dessa forma também:

' '.join(nome, endereco, telefone)
print(reg)

n deu.
'''

Resultado:

1 answer

2


Join does what you want, but on a list:

' '.join(['nome', 'endereco', 'telefone'])
'nome endereco telefone'

But if Voce, in the example, just wants to remove the semicolon from the original string, use replace, see the example:

reg = 'Carlos; Av. Marechal, 3; 392-323'
reg = reg.replace(';','')

print(reg)
Carlos Av. Marechal, 3 392-323
  • Thanks bro, that’s right I understood the . Join(), I was reading on the internet too and I forgot to assign who was using the function . Slit() so the sentence itself did not even change there yes I was able: https://repl.it/Juvb/3 - but thanks Voce taught me scheme of the list also!

Browser other questions tagged

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