The unofficial CircuitPython Reference

assignment operators

description

Assignment operators assign values to variables. Compound assignment operators will take a variable as input, do arithmetic on it and then assign the result back to the variable.

syntax

OperatorNameDescriptionExample SyntaxExample Result
=assignment operatorassign value to variablevar = 10var = 10
+=compound addadd variable to operand and assign result to variablevar += 10var = var + 10
-=compound subtractsubtract variable from operand and assign result to variablevar -= 10var = var - 10
*=compound multiplymultiple variable by operand and assign result to variablevar *= 10var = var * 10
/=compound dividedivide variable by operand and assign result to variablevar /= 10var = var / 10
%=compound modulodivide variable by operand and assign remainder to variablevar %= 10var = var % 10
**=compound exponentraise variable to power of operand and assign result to variablevar **= 10var = var ** 10
//=compound floor dividedivide variable by operand and assign result without decimalsvar //= 10var = var // 10

methods

parameters

returns

example code

serial output:

see also: