Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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.
string.split()
你可以使用这个:
print '\n'.join(x.split())
在哪里
x = 'this string' x.split() # ['this', 'string']
您不必使用split(). 这应该这样做。
split()
print x.replace(' ', '\n')
键盘。
它用换行符替换空格字符。
x="this string" for a in x.split(): print a