Hello hello! Welcome back to Part 2 of the Python Basics! Next let's start with some basic operations
Basic Operations
There are four core operations, arithmetic, comparison, logical and assignment.
As before, let's go ahead and create a new file called operations.py
1.Arithmetic OperationsArithmetic Operations are operations you can perform with numbers. Examples of these are:
Addition (+): Adds two numbers together.
result = 3 + 2 # result will be 5
Subtraction (-): Subtracts one number from another.
result = 3 - 2 # result will be 1
Multiplication (*): Multiplies two numbers.
result = 3 * 2 # result will be 6
Division (/): Divides one number by another.
result = 3 / 2 # result will be 1.5
Floor Division (//): Divides one number by another and rounds down to the nearest whole number.
result = 3 // 2 # result will be 1
Modulus (%): Gives the remainder of the division of two numbers.
result = 3 % 2 # result will be 1
Exponentiation (**): Raises one number to the power of another.
result = 3 ** 2 # result will be 9
Your Task
In a new file, let's call it operations.py, asign an output of each arithmetic operation above to a variable, and print each one out!
As always if you'd like a peek at an example answer click here
These operations compare two values and return a Boolean value (True
or False
).