Reputation: 71
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.
Upvotes: 3
Views: 2102
Reputation: 490143
You don't have to use split()
. This should do it.
print x.replace(' ', '\n')
It replaces the space character with the newline character.
Upvotes: 2
Reputation: 212825
You can use this:
print '\n'.join(x.split())
where
x = 'this string'
x.split() # ['this', 'string']
Upvotes: 8