How to replace space in a string with \n

Ian Clark ianhclark510 at gmail.com
Thu Jan 31 11:19:52 EST 2019


text = "The best day of my life!"
output = ''

for i in text:
 if i == ' ':
  output +='\n'
 else:
  output += i

print(output)

throwing my hat in the ring, not only is it .replace free it is entirely
method free

On Thu, Jan 31, 2019 at 3:41 AM ^Bart <gabriele1NOSPAM at hotmail.com> wrote:

> [Solved by myself and I'm happy!!! :)]
>
> text = "The best day of my life!"
>
> space = text[3]
>
> print (text.replace(space, "\n"))
>
> [Like what I said in another message, in the afternoon I'll ask to the
> teacher if for this exercise we're able to use .replace]
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list