Arithmetic Operators
Part of the Fundamentals section of Coddy's Python journey — lesson 10 of 77.
Operators are used to perform operations on values.
First we will discuss the most basic arithmetic operators, they may be familiar from math classes.
| Operator | Operation | Example |
|---|---|---|
| + | Addition | 3 + 2 = 5 |
| - | Subtraction | 3 - 2 = 1 |
| * | Multiplication | 3 * 2 = 6 |
| / | Division | 4 / 2 = 2.0 |
Let's see a usage example.
a = 3
b = 5
c = a + b # c holds 8Challenge
BeginnerWrite a code that initializes two variables, a and b, with the values 5.2 and 2.6 (respectively).
After that, initialize another variable c that will hold the result of a / b.
Cheat sheet
Arithmetic operators in Python:
| Operator | Operation | Example |
|---|---|---|
| + | Addition | 3 + 2 = 5 |
| - | Subtraction | 3 - 2 = 1 |
| * | Multiplication | 3 * 2 = 6 |
| / | Division | 4 / 2 = 2 |
Example usage:
a = 3
b = 5
c = a + b # c holds 8Try it yourself
# Type your code below
# Don't change the line below
print(f"a = {a}, b = {b}, c = {c}");This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 48Loops
For LoopWhile LoopBreakContinueRecap - FactorialThe Range FunctionNested LoopRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators9Functions
Declare a FunctionArgumentsReturnRecap - Sigma FunctionRecap - Validation FunctionDefault Values12Iterating Over Sequences
Iterating Over ElementsThe Enumerate FunctionIterating Over Strings Part 1Iterating Over Strings Part 2