我在找相当于Python的Python

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

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

推荐答案

不带参数的str.split()方法在空格上拆分:

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

Python相关问答推荐

@Property方法上的inspect.getmembers出现意外行为,引发异常

由于NEP 50,向uint 8添加-256的代码是否会在numpy 2中失败?

C#使用程序从Python中执行Exec文件

如何在类和classy-fastapi -fastapi- followup中使用FastAPI创建路由

根据二元组列表在pandas中创建新列

在Mac上安装ipython

无法使用requests或Selenium抓取一个href链接

SQLAlchemy Like ALL ORM analog

利用Selenium和Beautiful Soup实现Web抓取JavaScript表

如何使用scipy的curve_fit与约束,其中拟合的曲线总是在观测值之下?

考虑到同一天和前2天的前2个数值,如何估算电力时间序列数据中的缺失值?

使用BeautifulSoup抓取所有链接

pandas:对多级列框架的列进行排序/重新排序

以逻辑方式获取自己的pyproject.toml依赖项

Odoo16:模板中使用的docs变量在哪里定义?

Python pint将1/华氏度转换为1/摄氏度°°

如何在Gekko中使用分层条件约束

如何在一组行中找到循环?

如何在验证文本列表时使正则表达式无序?

在matplotlib中重叠极 map 以创建径向龙卷风图