"+ ="在Python中导致SyntaxError [英] "+=" causing SyntaxError in Python
本文介绍了"+ ="在Python中导致SyntaxError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
n = 1
p = 4
print n += p
给我:
File "p7.py", line 17
print n += p
SyntaxError: invalid syntax
如何解决此问题?
推荐答案
n += p
是Python中的语句,而不是返回可打印值的表达式.这不同于其他几种语言,例如Ruby,其中 everything 是一个表达式.
n += p
is a statement in Python, not an expression that returns a value you could print. This is different from a couple of other languages, for example Ruby, where everything is an expression.
您需要做
n += p
print n
这篇关于"+ ="在Python中导致SyntaxError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文