简体   繁体   English

Python3:使用正则表达式拆分+连接字符串-给出语法错误:无法分配给运算符

[英]Python3: Split+concatenate string with regex - giving syntax error: can't assign to operator

I am attempting to use a regex to split and concatenate a string but am getting an error message... as I can't see the problem, I am a little lost as to what to do. 我正在尝试使用正则表达式来拆分和连接字符串,但收到错误消息...由于看不到问题,我对操作方法有些迷失。

code: 码:

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

gives: 给出:

SyntaxError: can't assign to operator 语法错误:无法分配给运算符

the intended result would be: 预期结果将是:

M-L_centre = '0.0000 0.0000 0.2984'

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM