可以使用 Python split()
函数根据定义的分隔符将字符串分解为子字符串。它返回输入字符串中存在的所有单词的列表。
test = "I am learning Python."\nprint(test.split(" "))
运行结果如下:
['I', 'am', 'learning', 'Python.']
60、在 Python 中拆分字符串的最佳方法是什么?
可以使用 Python split()
函数根据定义的分隔符将字符串分解为子字符串。它返回输入字符串中存在的所有单词的列表。
test = "I am learning Python."\nprint(test.split(" "))
运行结果如下:
['I', 'am', 'learning', 'Python.']