gpt4 book ai didi

python - 在 Python 中速记添加/追加

转载 作者:太空狗 更新时间:2023-10-29 18:14:23 24 4
gpt4 key购买 nike

我喜欢在 PHP 中我可以执行以下操作

$myInteger++;
$myString += 'more text';

使用 Python 我必须执行以下操作

myInteger = myInteger + 1
myString = myString + "more text"

有没有更好的方法在 Python 中添加或附加到变量?

最佳答案

Python 没有递增 (++) 和递减 (--) 运算符,但它有 += 运算符(和 -= 等),因此您可以这样做:

myInteger += 1
myString += "more text"

关于python - 在 Python 中速记添加/追加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/433795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com