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:
Output:
Combining Strings
You can also combine text using the + operator, Example:
Output:
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.
0 Comments