Variable
a name identifier in memory that stores the data during the execution of the program. Python is dynamic and declaring a variable is very simple. a = 10
is simply a variable assignment statement.
Assignment operator
In Python assignment operator is simply single = sign , the value on the right get assigned to the name identifier on the left. Below are some of the example assignmentsa = 20
b = 40
total = a
total = a + b
Arithmetic operator
In Python arithmetic operator include + - * / %
Examples :
Addition c = a + b
Calculates the value of a + b and assigns to c
Substraction c = a - b
Substracts the value of b from a and assigns to c
Multiplication c = a * b
Multiplies the value of a with b and assigns to c
Exponentiation c = a ** b
Assigns a power b example 3 ** 2 = 9
Division c = a / b
Divides the value of b from a and assign the new value to c
Floor Division c = a // b
Divides the value of b from a and yeild the real number of higher end and assign the new value to c
Modulus c = a % b
gives the remainder value as the output 9 % 2 gives remainder 1
Arithmetic plus Assignment short form
Arithmetic operator can be used along with the assignment operator to form a shorter statement
Statement | Full Statement |
---|---|
a += b | a = a + b |
a -= b | a = a – b |
a *= b | a = a * b |
a /= b | a = a / b |
a //= b | a = a // b |
a %= b | a = a % b |
a **= b | a = a ** b |