python divmod function (25)

 

 

A .divmod () function description

    divmod () function is also built-in function python, which is the calculation result divisor and the remainder combined, it returns a tuple containing the quotient and remainder of (a // b, a% b)

divmod (x, y)

 

    Parameters: x, y are numbers, may also be shaped float, x is a molecule, y is the denominator;

    Return Value: returns a tuple (x // y, x% y);

 

Two .divmod () function uses

# ! Usr / bin / env Python 
# - * - Coding: UTF-8 _ * - 
"" " 
@author: Why grief 
@Blog (personal blog address): shuopython.com 
@WeChat Official the Account (micro-channel public number): Ape said Python 
@Github: www.github.com 
 
@file: python_divmod.py 
@time: 2019/12/07 21:25 
 
@Motto: short step a thousand miles, no small streams into a mighty torrent, wonderful life program need to make unremitting efforts to accumulate! 
"" " 
 
Print ( " {} " .format (of the type (divmod (9,6 ))))
 Print ( " {} " .format (divmod (9,6 ))) 
 
Print ( " { } " .format (of the type (divmod (9.2,6.6))))
print("{}".format(divmod(9.2,6.6)))

 

    Output:

<class 'tuple'>
(1, 3)
<class 'tuple'>
(1.0, 2.5999999999999996)

 

 

    Note: divmod () function accepts only integer or floating point type parameter string can not be used, otherwise it will complain!

 

 

you may also like:

    1. anonymous function lambda

    Logical operators 2.renturn

    3. dictionary derivations

    4. List comprehension

 

    Reproduced please specify: ape say Python  »  Python function divmod

 

Technical exchanges, business cooperation please contact bloggers
Scan code or search: ape say python
No public python tutorial
Ape say python
No. sweep the micro-channel public concern

Guess you like

Origin www.cnblogs.com/shuopython/p/12130168.html