eLearning

We are a professional site that will give you the strongest methods to get learn and we will teach you everything about programming and technology

PYTHON

Breaking News

PYTHON
PYTHON
جاري التحميل ...

Python Transactions: Python Operators Lesson 2

 Python transactions: python operators



Arithmetic operators in Python language

Parameters in the Python language are divided into several parameters, and there are four basic parameters, which are explained below. Arithmetic parameters will be explained in this lesson and the rest of the transactions in other lessons

Arithmetic operators

Assignment operators. Value assignment parameters

Comparison operators

Logical operators. Boolean operators

Arithmetic operators

  • Plus +
  • Subtraction -
  • Multiplication *
  • division /
  • Remainder division%
  • Exponent **
  • Correct division //

And we will explain it with an example

num1 = 6

num2 = 2

print (num1 + num2)

It will print 8

print (num1-num2)

4 will be printed

print (num1 * num2)

12 will be printed

print (num1 / num2)

3 will be printed

print (num1% num)

It will print 0

print (num1 ** num2)

It will print 36

print (num1 // num2)

3 will be printed

Note: Some operators are not used only for the operators between numbers. They can be used with arrays and tally (we will learn about them later).

Example:

list_1 = ["the", "ten"]

list_2 = [10, "dev"]

print (list_1 + list_2)

Will be printed:

["the", "ten", 10, "dev"]

Another example:

print (list_1 * 2)

Will be printed:

["the", "ten", "the", "ten"]

I'll explain the% sign or the remainder

The result of dividing 6/2 is 3 (2 * 3 = 6), while the remainder of the division is zero.

7/2 division gives 3 (1 + 2 * 3 = 7)

The remainder is 1

Priorities for arithmetic operations according to implementation

1-- ()

2-- **

3-- * /

4-- + -

Example for illustration

num1 = 10

num2 = 5

num3 = 4

print (num1 + num2 * num3)

Some might think that the implementation of this process is as follows

It is adding the value of the variable num1 with the value of the variable num2, then multiplying this result by the value of the variable num3

However, this is not correct. See the priorities for implementing the arithmetic transactions that were explained. We find that the program will first multiply the value of the variable. num2 in the value of the variable num3, then add this result to the value of the variable num3, so the result is 30

some notes :

- In the event that there are more than one treatment with the same priority of implementation, the implementation shall be done from left to right.

- In the case of a desire to give priority to any operation, implementation is placed inside parentheses ().


عن الكاتب

ADMIN

التعليقات


اتصل بنا

If you like the content of our blog, we hope to stay in constant contact, just enter your email to subscribe to the blog express mail so that you will receive the new blog first-hand, and you can send a message by clicking the next button ...

جميع الحقوق محفوظة

eLearning