Python negative modulus operation example

Example: 340%60 = 40, how did it come from?

340 – 60*5 = 40

340 – (The positive integer smaller than 340 that is divisible by 60) =. 40

**If it is negative: **

As shown:

You can also think about it differently,

For example:

1 %3 = 1

Supplementary knowledge: the calculation method of calculating the remainder of negative numbers in python and the points of attention in exponentiation operation

The calculation method of calculating the remainder of negative numbers in python

1. Divide operation (after the result of division is calculated, round down)

Use the division operation //

1 // 203// 2110// 3310// -3-4

10 / 3 = 3.3333

Therefore: 10 // 3.33 is rounded down to 3 in 3

10 / -3 = -3.333

10 // -3 is rounded down to -3.33 to equal -4

*2. Find the remainder (use %) x% y is equivalent to x – (x // y)y

  • x% y is equivalent to x – (x // y)y
10 %-3-2-10%32

10 How is% -3 = -2 calculated?

x% y is equivalent to x – (x // y)y

10 // -3 = -4 has been calculated above

10 % -3 = 10 – (-4)(-3) = 10 – 12 = -2

10 % 3 = -10 – (-4)*3 = -10 + 12 = 2

One point to note in exponentiation

**3. Use **** for exponentiation

-3**2-9(-3)**29

The precedence of the exponentiation operator is higher than the negation (-).

The above python negative modulus calculation example is all the content shared by the editor, I hope to give you a reference.

Recommended Posts

Python negative modulus operation example
Python list comprehension operation example summary
Example operation of python access Alipay
Python file operation
Python object-oriented example
python operation kafka
Example of feature extraction operation implemented in Python
Python3.7 debugging example method
Python operation SQLite database
Python operation yaml instructions
Python interpolate interpolation example
Python-openCV open operation example
Python automated operation and maintenance 2
Python operation Excel merge cells
Python3 logging log package example
Python regular expression example code
Python output mathematical symbols example
Python automated operation and maintenance 1
Python iterable object de-duplication example
Python one-dimensional two-dimensional interpolation example
Quick start Python file operation
Python draw bar graph (bar graph) example
Python right alignment example method
Python regular expression learning small example
Python judges positive and negative numbers
Python calculation of information entropy example
Python waterfall line indicator writing example
Python file operation basic process analysis
Implementation of python selenium operation cookie
Python ATM function implementation code example
Python example to calculate IV value
Python decorator simple usage example summary
Some examples of python operation redis
Python tcp transmission code example analysis
The operation of python access hdfs
Python handles operation code to execl
Python requests module session code example
Python verification code interception identification code example