在Python中的空白处分割字串

发布于 2021-02-02 23:12:18

我正在寻找相当于的Python

String str = "many   fancy word \nhello    \thi";
String whiteSpaceRegex = "\\s";
String[] words = str.split(whiteSpaceRegex);

["many", "fancy", "word", "hello", "hi"]
关注者
0
被浏览
58
1 个回答
  • 面试哥
    面试哥 2021-02-02
    为面试而生,有面试问题,就找面试哥。

    str.split()不带参数的方法在空白处分割:

    >>> "many   fancy word \nhello    \thi".split()
    ['many', 'fancy', 'word', 'hello', 'hi']
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看