python中的 += 语法的使用

python中有个缩略的写法,如下

a = a +1 等同于 a +=1

发现了一个有趣之处,+=的写法中间不能有空格,否则报错,测试如下

Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> a=1
>>> a +=1
>>> a
2
>>> a+ = 1
SyntaxError: invalid syntax
>>> 

 

原文地址:https://www.cnblogs.com/feng-hao/p/11322179.html