Pythonで空白で文字列を分割する [重複] 質問する

Pythonで空白で文字列を分割する [重複] 質問する

Python版を探しています

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

["many", "fancy", "word", "hello", "hi"]

ベストアンサー1

str.split()引数のないメソッドは空白で分割されます:

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

おすすめ記事