37,719
社区成员
发帖
与我相关
我的任务
分享
def break_words(stuff):
"""this fuction will break up words for us."""
#split的作用,是将stuff的每个单词分割出来,中间加入空格
words=stuff.split(' ')
return words
>>> words = "abc def".split()
>>> words[0]
26: 'abc'
>>> words[0][0]
27: 'a'
>>> sentence = "a sentence\tthat \thas different\nspace characters"
>>> sentence.split(' ')
28: ['a', '', 'sentence\tthat', '\thas', 'different\nspace', 'characters']
>>> sentence.split()
29: ['a', 'sentence', 'that', 'has', 'different', 'space', 'characters']
>>> sentence.split('\t')
30: ['a sentence', 'that ', 'has different\nspace characters']
>>> "abc"
'abc'
>>> "ab'c"
"ab'c"
>>> 'ab"c'
'ab"c'
>>>