Python Basic Operations

Hey friends 👋 welcome back, In the last lesson, we learned about Python data types, Today, we are going to learn about basic operations, which allow us to do calculations and combine values stored in variables, Operations are essential because they help us work with numbers and other data in our programs.

Arithmetic Operations

Python can perform all standard arithmetic operations, Here are the main ones:
1, Addition +, Example: a = 10, b = 5, sum = a + b
2, Subtraction -, Example: difference = a - b
3, Multiplication *, Example: product = a * b
4, Division /, Example: quotient = a / b (always returns a float)
5, Floor Division //, Example: floor = a // b (returns whole number)
6, Modulus %, Example: remainder = a % b (returns remainder)
7, Exponent **, Example: power = a ** b (a raised to the power of b)

Example code:

a = 10 b = 3 print("Addition:", a + b) print("Subtraction:", a - b) print("Multiplication:", a * b) print("Division:", a / b) print("Floor Division:", a // b) print("Remainder:", a % b) print("Exponent:", a ** b)

Output:

Addition: 13 Subtraction: 7 Multiplication: 30 Division: 3.3333333333333335 Floor Division: 3 Remainder: 1 Exponent: 1000

Combining Strings

You can also combine text using the + operator, Example:

first_name = "Yusuf" last_name = "Adeleke" full_name = first_name + " " + last_name print("Full Name:", full_name)

Output:

Full Name: Yusuf Adeleke

Practice Time

Create a Python file called basic_operations.py and try these exercises, 1, Add two numbers and print the result, 2, Subtract one number from another and print the result, 3, Multiply two numbers and print the result, 4, Divide two numbers and print the result, 5, Combine two strings and print the full result

Great job, You just learned how to perform basic operations in Python, In the next lesson, we will explore Python Input and Output, where we will learn how to get information from users and display it on the screen, We will soon be launching our YouTube channel, where we are going to post step-by-step video tutorials on Python and other tech skills, These videos will make learning easier and more visual, helping beginners follow along confidently.