Step 1: Learning the basics Part 2

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 Operations


Arithmetic 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


2.Comparison Operations

These operations compare two values and return a Boolean value (True or False).


In this tutorial we will use our IDE as source code editor, where we will write and edit our code. If you don't have an IDE installed you can go ahead and install Visual Studio Code