Exponents, Precedence and Augmented Assignment

Exponentiation and negation

Two stars raise a number to a power.
Negation is a unary operator. It applies to only one operand. Other operations such as +, -, *, /, // and % are binary operators: they apply to two operands.

Operator precedence

PrecedenceOperatorOperation
highest**exponentiation
-negation
*, /, //, %multiplication, division, floor division, modulus (left to right)
lowest+, -addition, subtraction (left to right)
Operators on the same row are applied left to right. Exponentiation, however, is applied right to left. Expressions in parentheses are evaluated first (PEMDAS).

Augmented assignment

An augmented assignment combines an assignment statement with an operator to make the statement more concise.
ShorthandEquivalent version
variable += valuevariable = variable + value
variable -= valuevariable = variable - value
variable *= valuevariable = variable * value
variable /= valuevariable = variable / value
variable %= valuevariable = variable % value

String concatenation

Two strings can be combined, or concatenated, using the + operator.
Concatenating a string and a number raises a TypeError. You must first cast the number into a string using str().