Nearby lessons

30 of 159

Python - Arithmetic Operators

📌 What You Will Learn
  • Identify the seven arithmetic operators in Python
  • Use +, -, *, and / on numbers
  • Use % for remainder and // for floor division
  • Calculate powers with the ** operator
  • Concatenate and repeat strings with + and *
  • Apply operator precedence and parentheses in expressions

Introduction

Arithmetic operators are used to perform mathematical calculations in Python.

These operators work with numbers and, in some cases, with strings.

Arithmetic Operators List

Operator Meaning
+Addition
-Subtraction
*Multiplication
/Division
%Modulus
//Floor Division
**Exponent

1. Addition Operator (+)

The addition operator is used to add two values.

Example - Addition

Loading editor…

Example - Addition with Float Values

Loading editor…

Addition with Strings

The + operator can also join (concatenate) two strings.

Example - String Concatenation

Loading editor…

Important Note

For string concatenation, both operands must be strings.

Example - Invalid String Addition

Loading editor…

2. Subtraction Operator (-)

The subtraction operator is used to subtract one value from another.

Example - Subtraction

Loading editor…

Example - Subtraction with Float Values

Loading editor…

Important Note

The subtraction operator cannot be used with strings.

Example - Invalid String Subtraction

Loading editor…

3. Multiplication Operator (*)

The multiplication operator is used to multiply two values.

Example - Multiplication

Loading editor…

Example - Multiplication with Float

Loading editor…

String Repetition Using *

The * operator can repeat a string multiple times.

Example - String Repetition

Loading editor…

Important Note

For string repetition, one operand must be an integer.

Example - Invalid String Multiplication

Loading editor…

4. Division Operator (/)

The division operator divides one value by another.

Important Rule: The division operator always returns a floating-point value.

Example - Division

Loading editor…

Example - Division with Decimal Result

Loading editor…

Division by Zero

Dividing a number by zero causes an error.

Example - Division by Zero

Loading editor…

5. Floor Division Operator (//)

The floor division operator returns only the floor (quotient) value.

The decimal part is removed.

Example - Floor Division

Loading editor…

Example - Floor Division with Float

Loading editor…

Difference Between / and //

/ //
Returns a floating-point result. Returns the floor value.
Example: 10 / 3 = 3.3333... Example: 10 // 3 = 3

6. Modulus Operator (%)

The modulus operator returns the remainder after division.

Example - Modulus

Loading editor…

Explanation

Expression Result
10 % 2 0
10 % 3 1

Usage of Modulus Operator

The modulus operator is commonly used to:

  • Check even numbers.
  • Check odd numbers.
  • Check divisibility.

Example - Check Even Number

Loading editor…

7. Exponent Operator (**)

The exponent operator is used to calculate the power of a number.

Example - Exponent

Loading editor…

Explanation

2 ** 3

means

2 × 2 × 2 = 8
        

Example - Another Exponent

Loading editor…

Operator Precedence

Python follows operator precedence while evaluating arithmetic expressions.

Example - Operator Precedence

Loading editor…

Explanation

First:

2 * 3 = 6

Then:

10 + 6 = 16
        

Using Parentheses

Parentheses change the order of execution.

Example - Parentheses

Loading editor…

Arithmetic Operators with Variables

Loading editor…

Real World Usage

Arithmetic operators are commonly used in:

  • Billing systems
  • Banking applications
  • Marks calculation
  • Scientific calculations
  • E-commerce applications
📝 Key Takeaways
  • The seven arithmetic operators are +, -, *, /, %, //, and **
  • The division operator / always returns a floating-point value
  • Dividing a number by zero raises a ZeroDivisionError
  • The % operator returns the remainder after division
  • The * operator repeats a string, and + concatenates strings
  • Parentheses change the order in which expressions are evaluated

🧠 Test Your Knowledge

8 Questions
Progress: 0 / 8

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.