我想知道如何逐个单词地遍历字符串。
上面的代码将会输出:
但我需要以下输出结果:
string = "this is a string"
for word in string:
print (word)
上面的代码将会输出:
t
h
i
s
i
s
a
s
t
r
i
n
g
但我需要以下输出结果:
this
is
a
string