小编Rab*_*ole的帖子

Python内联增加多个变量

为什么这样做

>> x, y = (1, 2)
>> print x, y
1 2
Run Code Online (Sandbox Code Playgroud)

但是增加会导致语法错误.

>> x, y -= (1, 2)
SyntaxError: illegal expression for augmented assignment
Run Code Online (Sandbox Code Playgroud)

有没有不同的方式,我期待:

>> x, y -= (1, 2)
>> print x, y
0 0
Run Code Online (Sandbox Code Playgroud)

python operators

19
推荐指数
2
解决办法
4234
查看次数

正则表达式组引用错误

p = r'([\,|\.]\d{1}$)'
re.sub(p, r"\1", v)
Run Code Online (Sandbox Code Playgroud)

工作,但我想在捕获组中添加零,而不是用捕获组'10'替换,我该怎么做?

re.sub(p, r"\10", v)
Run Code Online (Sandbox Code Playgroud)

失败:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 151, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 275, in filter
    return sre_parse.expand_template(template, match)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_parse.py", line 802, in expand_template
    raise error, "invalid group reference"
sre_constants.error: invalid group reference
Run Code Online (Sandbox Code Playgroud)

python regex

4
推荐指数
1
解决办法
2759
查看次数

标签 统计

python ×2

operators ×1

regex ×1