Operators - Data Manipulation Tools


The print statement can allow you to use Python as a calculator.  The math operators are very similar to most calculators.


OperatorNameExampleMeaning
+Additionx + yAdd two operands or unary plus
-Subtractionx - ySubtract right operand from the left or unary minus
*Multiplicationx * yMultiply two operands
/Divisionx / yDivide left operand by the right (always results into float)
%Modulusx % yThe remainder of the division of left operand by the right
**Exponentiationx ** yThe left operand raised to the power of the right
//Floor Divisionx // yA division that results in the whole number adjusted to the left in the number line

*Notes on division:

  1. The result of integer division is always rounded to the nearest integer value that is less than the real (not rounded) result.
  2. This is very important - Rounding always goes to the lesser integer.
  3. Do not try to: 

    • perform a division by zero
    • perform an integer division by zero
    • find a remainder of a division by zero

Practice

Objectives

  • becoming familiar with the concept of numbers, operators, and arithmetic operations in Python;
  • experimenting with Python code

Scenario

In the compiler, write the provided expressions inside the print() functions.

a) print(2*4)

b) print(2**4)

c) print(2.*4)

d) print(2/4)

e) print(2//4)

f) print(-2/4)

g) print(-2//4)

h) print(2%4)

i) print(2%-4)