coding180 icon
Coding180
Arithmetic Operators: Addition, Subtraction, Multiplication, Division, Modulus, and Exponentiation:

Arithmetic Operators: Addition, Subtraction, Multiplication, Division, Modulus, and Exponentiation:

Home > Tutorials > Python for beginners > Operators


It's important to understand the basics of arithmetic operators in Python. These operators include addition, subtraction, multiplication, division, modulus, and exponentiation. In this article, we'll go through each operator and provide examples and exercises that will help you get started.

Addition (+)

The addition operator is denoted by the "+" symbol. It is used to add two or more values and produce their sum. Here's an example:

a = 5
b = 10
c = a + b
print(c)

In this example, we assigned the value 5 to the variable a and the value 10 to the variable b. We then added a and b and assigned the result to the variable c. Finally, we printed the value of c, which is 15.

Exercise 1

Write a program that adds two numbers, 25 and 30, and print the result.

Subtraction (-)

The subtraction operator is denoted by the "-" symbol. It is used to subtract one value from another and produce the difference. Here's an example:

a = 10
b = 5
c = a - b
print(c)

In this example, we assigned the value 10 to the variable a and the value 5 to the variable b. We then subtracted b from a and assigned the result to the variable c. Finally, we printed the value of c, which is 5.

Exercise 2

Write a program that subtracts 15 from 100 and prints the result.

Multiplication (*)

The multiplication operator is denoted by the "*" symbol. It is used to multiply two or more values and produce their product. Here's an example:

a = 5
b = 10
c = a * b
print(c)

In this example, we assigned the value 5 to the variable a and the value 10 to the variable b. We then multiplied a and b and assigned the result to the variable c. Finally, we printed the value of c, which is 50.

Exercise 3

Write a program that multiplies 7 and 8 and prints the result.

Division (/)

The division operator is denoted by the "/" symbol. It is used to divide one value by another and produce the quotient. Here's an example:

a = 10
b = 2
c = a / b
print(c)

In this example, we assigned the value 10 to the variable a and the value 2 to the variable b. We then divided a by b and assigned the result to the variable c. Finally, we printed the value of c, which is 5.

Exercise 4

Write a program that divides 100 by 5 and prints the result.

Modulus (%)

The modulus operator is denoted by the "%" symbol. It is used to find the remainder when one value is divided by another. Here's an example:

a = 10
b = 3
c = a % b
print(c)

In this example, we assigned the value 10 to the variable a and the value 3 to the variable b. We then found the remainder when a is divided by b and assigned the result to the variable c. Finally, we printed the value of c, which is 1.

Exercise 5

Write a program that finds the remainder when 50 is divided by 7.

Exponentiation (**)

The exponentiation operator is denoted by the "**" symbol. It is used to raise one value to the power of another. Here's an example:

a = 2
b = 3
c = a ** b
print(c)

In this example, we assigned the value 2 to the variable a and the value 3 to the variable b. We then raised a to the power of b and assigned the result to the variable c. Finally, we printed the value of c, which is 8.

Exercise 6

Write a program that calculates 2 raised to the power of 10 and prints the result.

Conclusion

Arithmetic operators are essential in programming, and Python makes it easy to perform arithmetic operations using its built-in operators. By understanding these operators and practicing with the exercises provided


user

Robort Gabriel

Lagos, Nigeria

Freelance Web Developer, Native Android Developer, and Coding Tutor.

Skills
  • UI / UX
  • JavaScript
  • Python
  • PHP
  • Kotlin
  • Java
  • Bootrap
  • Android
  • Laravel