You are here

Operators and operands

23 February, 2015 - 11:51

Operators are special symbols that represent computations like addition and multiplication. The values the operator is applied to are called operands.

The operators +, -, *, / and ** perform addition, subtraction, multiplication, division and exponentiation, as in the following examples:

20+32   hour-1   hour*60+minute   minute/60   5**2   (5+9)*(15-7)

The division operator might not do what you expect:

>>> minute = 59>>> minute/600

The value of minute is 59, and in conventional arithmetic 59 divided by 60 is 0.98333, not 0. The reason for the discrepancy is that Python is performing floor division 1.

When both of the operands are integers, the result is also an integer; floor division chops off the fraction part, so in this example it rounds down to zero.

If either of the operands is a floating-point number, Python performs floating-point division, and the result is a float:

>>> minute/60.00.98333333333333328