Product Site

5.1.7.18. Arithmetic Methods

Note

The syntax diagram above is for the non-prefix operators. For the prefix operators, omit the parentheses and argument.

Returns the result of performing the specified arithmetic operation on the receiver object. The receiver object and the argument must be valid numbers. The arithmetic_operator can be:
+

Addition
-

Subtraction
*

Multiplication
/

Division
%

Integer division (divide and return the integer part of the result)
//

Remainder (divide and return the remainder—not modulo, because the result can be negative)
**

Exponentiation (raise a number to a whole-number power)
Prefix -

Same as the subtraction: 0 - number
Prefix +

Same as the addition: 0 + number

See Chapter 10, Numbers and Arithmetic for details about precision, the format of valid numbers, and the operation rules for arithmetic. Note that if an arithmetic result is shown in exponential notation, it might have been rounded.
Example 5.54. String class — arithmetic methods
Say 5+5     -->    10
Say 8-5     -->     3
Say 5*2     -->    10
Say 6/2     -->     3
Say 9//4    -->     1
Say 9%4     -->     2
Say 2**3    -->     8
Say +5      -->     5             /* Prefix +  */
Say -5      -->    -5             /* Prefix -  */