Python - Operators

Arithmetic Operators  Python Arithmetic Operations Shortcuts

Python Arithmetic Operations Shortcuts

Operation Symbol Description Example
Addition + Adds two numbers 3 + 2 → 5
Subtraction - Subtracts one number from another 5 - 3 → 2
Multiplication * Multiplies two numbers 4 * 3 → 12
Division / Divides one number by another (float result) 8 / 4 → 2.0
Floor Division // Divides and returns the integer part (floor) 7 // 3 → 2
Modulus % Returns the remainder of division 7 % 3 → 1
Exponentiation ** Raises a number to the power of another 2 ** 3 → 8
Increment += Adds a value to a variable (in-place addition) x += 5 → x = x + 5
Decrement -= Subtracts a value from a variable (in-place) x -= 2 → x = x - 2
Multiply and Assign *= Multiplies a variable by a value (in-place) x *= 3 → x = x * 3
Divide and Assign /= Divides a variable by a value (in-place) x /= 2 → x = x / 2
Floor Divide and Assign //= Floor divides a variable by a value (in-place) x //= 2 → x = x // 2
Modulus and Assign %= Finds the modulus of a variable (in-place) x %= 4 → x = x % 4
Exponent and Assign **= Raises a variable to the power of a value (in-place) x **= 2 → x = x ** 2

Comparison Operators

Logical Operators


No comments:

Post a Comment