6 Arithmetic Operator

  • Standard arithmetic operators are similar

  • Exponentiation is different in R & Python


6.1 R

x <- 5; y <- 3 OR x = 5; y = 3

Operator Explanation Example
+ Addition x + y
- Subtraction x - y
* Multiplication x * y
/ Division x / y
%% Modulus x %% y
%/% Integer division x %/% y
^ (**) Exponentiation x ^ y; x ** y
() Parenthesis (precedence rule) (x + y)*3


6.2 Python

x = 5; y = 3

Operator Explanation Example
+ Addition x + y
- Subtraction x - y
* Multiplication x * y
/ Division x / y
% Modulus x % y
// Integer division x // y
** Exponentiation x ** y
() Parenthesis (precedence rule) (x + y)*3
other C-type operation for quick assign x += y

In python, ^ is a bitwise exclusive OR (XOR) operator