我正在尝试使用正则表达式来拆分和连接字符串,但收到错误消息...由于看不到问题,我对如何处理感到有些迷茫。

码:

import re
s = 'Defect centre is at   0.0000   0.0000   0.2984  Frac'
M-L_centre = ' '.join(re.finditer('[\d.]+', s))

给出:



预期结果将是:
M-L_centre = '0.0000 0.0000 0.2984'

最佳答案

M-L_centre中带有连字符,因此它是一个算术表达式而不是变量(或任何您想要的变量),因此您无法为其分配值。

关于python - Python3 : Split+concatenate string with regex - giving syntax error: can't assign to operator,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25189662/

10-11 22:26
查看更多