Reputation: 111059
I like that in PHP I can do the following
$myInteger++;
$myString += 'more text';
With Python I must do the following
myInteger = myInteger + 1
myString = myString + "more text"
Is there a better way to add or append to a variable in Python?
Upvotes: 15
Views: 23613
Reputation: 8343
You could do it in the same way you are doing it in PHP:
var += 1
But my advice is to write it down clear:
var = var + 1
Upvotes: 3
Reputation: 176743
Python doesn't have the increment (++) and decrement (--) operators, but it does have the += operator (and -=, etc.) so you can do this:
myInteger += 1
myString += "more text"
Upvotes: 37