+= 是什么意思

南迪尼

some_product += another_product

我刚刚开始学习 python,所以我对这门语言很陌生,我正在努力理解 += 的含义。

凯德拉克

这是一个如何向变量添加数字的非常简单的示例:

a = 1
# we want to add to a 5
a = a + 5
print(a)
# output: 6

要么:

a = 1
a += 5 # equivalent with a = a + 5
print(a)
# output: 6

类似:some_product += another_product相当于:some_product = some_product + another_product,假设您的变量是整数或其他数字类型

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章