Arithmetic Operators in Python

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 21:- Arithmetic Operators in Python

In Python, arithmetic operators are used to perform basic arithmetic operations on numbers. These operators allow you to add, subtract, multiply, divide, and perform other mathematical operations. Here are the common arithmetic operators in Python:

  1. Addition: + Adds two numbers or concatenates two strings.

Example:

pythonCopy code

a = 5 b = 3 result = a + b print(result)  # Output: 8 str1 = "Hello, " str2 = "World!" result_str = str1 + str2 print(result_str)  # Output: Hello, World!

  1. Subtraction: - Subtracts the second number from the first number.

Example:

pythonCopy code

a = 10 b = 3 result = a - b print(result)  # Output: 7

  1. Multiplication: * Multiplies two numbers or repeats a string.

Example:

pythonCopy code

a = 5 b = 4 result = a * b print(result)  # Output: 20 str1 = "Hello! " result_str = str1 * 3 print(result_str)  # Output: Hello! Hello! Hello!

  1. Division: / Divides the first number by the second number, and the result is a float.

Example:

pythonCopy code

a = 10 b = 2 result = a / b print(result)  # Output: 5.0 (float) c = 15 d = 4 result2 = c / d print(result2)  # Output: 3.75 (float)

  1. Floor Division: // Divides the first number by the second number, and the result is the floor value (rounded down) of the division as an integer.

Example:

pythonCopy code

a = 10 b = 3 result = a // b print(result)  # Output: 3 (integer) c = 15 d = 4 result2 = c // d print(result2)  # Output: 3 (integer)

  1. Modulus: % Returns the remainder of the division between the first number and the second number.

Example:

pythonCopy code

a = 10 b = 3 result = a % b print(result)  # Output: 1

  1. Exponentiation: ** Raises the first number to the power of the second number.

Example:

pythonCopy code

a = 2 b = 3 result = a ** b print(result)  # Output: 8

These arithmetic operators are fundamental in performing mathematical calculations and operations in Python. They can be used with both numerical values and strings, making Python a versatile language for various applications.

4. Operators

Comments: 0

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?