Analysis of divmod digital processing functions in python, pythondivmod

Source: Internet
Author: User
Tags integer division

Analysis of divmod digital processing functions in python, pythondivmod

Divmod (a, B) Function

Chinese description:

The divmod (a, B) method returns a // B (Division) and the remainder of a to B.

The returned result type is tuple.

Parameters:

A and B can be numbers (including plural numbers)

Version:

Complex numbers cannot be processed before python2.3.

English description:

Take two (non complex) numbers as arguments and return a pair of numbers consisting of their quotient and remainder when using long division. with mixed operand types, the rules for binary arithmetic operators apply. for plain and long integers, the result is the same as (a // B, a % B ). for floating point numbers the result is (q, a % B), where q is usually math. floor (a/B) but may be 1 less than that. in any case q * B + a % B is very close to a, if a % B is non-zero it has the same sign as B, and 0 <= abs (a % B) <abs (B ).

Changed in version 2.3: Using divmod () with complex numbers is deprecated.

Python code example:

>>> divmod(9,2)(4, 1)>>> divmod(11,3)(3, 2)>>> divmod(1+2j,1+0.5j)((1+0j), 1.5j)

PS: Python standard library: built-in function divmod (a, B)

This function implements dividing a by B and then returns the tuples between the operator and the remainder. If both parameters a and B are integers, integer division is adopted, and the result is equivalent to (a // B, a % B ). If a or B is a floating point number, it is equivalent to (math. floor (a/B), a % B ).

Example:

#divmod() print('divmod(2, 4):', divmod(2, 4)) print('divmod(28, 4):', divmod(28, 4)) print('divmod(27, 4):', divmod(27, 4)) print('divmod(25.6, 4):', divmod(25.6, 4)) print('divmod(2, 0.3):', divmod(2, 0.3)) 

The output result is as follows:

divmod(2, 4): (0, 2)divmod(28, 4): (7, 0)divmod(27, 4): (6, 3)divmod(25.6, 4): (6.0, 1.6000000000000014)divmod(2, 0.3): (6.0, 0.20000000000000007)

Summary

The above is a small Editor to introduce you to the python divmod digital processing function analysis, I hope to help you, if you have any questions, please leave a message, the small editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.