So say I have
x = "this string"
I'm trying to print the two words on different lines. I'm thinking that I need to use string.split() in some way but I'm not sure how.
You can use this:
print '\n'.join(x.split())
where
x = 'this string'
x.split() # ['this', 'string']
You don't have to use split(). This should do it.
print x.replace(' ', '\n')
CodePad.
It replaces the space character with the newline character.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With