bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/Python/Foundations Practice
Python•Foundations Practice

Python Arithmetic Operators

Arithmetic Operators

Arithmetic operators are used with numeric values to perform common mathematical operations:

Operator

Name

Example

Try it

+

Formula

Addition x + y

Try it »

Formula

Subtraction x - y

Try it » *

Formula

Multiplication x * y

Try it » /

Formula

Division x / y

Try it » %

Modulus x % y

Try it » Exponentiation x y Try it » // Floor division x // y Try it »

Examples

Here is an example using different arithmetic operators:

Example x = 15 y = 4 print(x + y)
print(x - y)
print(x * y)
print(x / y)
print(x % y)
print(x ** y)
print(x // y)

Division in Python

Python has two division operators:

/ - Division (returns a float) // - Floor division (returns an integer)

Example

Division always returns a float:

x = 12 y = 5 print(x / y)

Example

Floor division always returns an integer. It rounds DOWN to the nearest integer:

x = 12 y = 5 print(x // y)

Previous

Python Operators

Next

Python Assignment Operators