Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shorthand adding/appending in Python

Tags:

python

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?

like image 880
Teifion Avatar asked Jan 11 '09 21:01

Teifion


1 Answers

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"
like image 134
Paige Ruten Avatar answered Sep 29 '22 22:09

Paige Ruten