python中divmod_divmod()函数以及Python中的示例

python中divmod

Python divmod()函数 (Python divmod() function)

divmod() function is a library function, it is used to get the quotient and remainder of given values (dividend and divisor), it accepts two arguments 1) dividend and 2) divisor and returns a tuple that contains quotient and remainder.

divmod()函数是一个库函数,用于获取给定值的商和余数 ( 被除数和除数 ),它接受两个参数1) 除数和2) 除数,并返回一个包含商和余数的元组。

Syntax:

句法:

    divmod(dividend, divisor)

Parameter(s):

参数:

  • dividend – a number to be divided.

    红利 –要除的数字。

  • divisor – a number to be divided with.

    除数 –要除的数字。

Return value: tuple – it returns a tuple containing quotient and remainder.

返回值: tuple –返回包含商和余数的元组。

Example:

例:

    Input:
    a = 10  #dividend
    b = 3   #divisor

    # finding quotient and remainder
    result = divmod(a,b)
    print("result = ", result)
    
    Output:
    result =  (3, 1)

Python code to find quotient and remainder of two numbers

Python代码查找两个数字的商和余数

# python code to demonstrate example of 
# divmod() number

a = 10  #dividend
b = 3   #divisor

print("return type of divmod() function: ", type(divmod(a,b)))

# finding quotient and remainder
result = divmod(a,b)
print("result = ", result)

# float values
a = 10.23  #dividend
b = 3.12   #divisor

# finding quotient and remainder
result = divmod(a,b)
print("result = ", result)

Output

输出量

return type of divmod() function:  <class 'tuple'>
result =  (3, 1)
result =  (3.0, 0.8700000000000001)


翻译自: https://www.includehelp.com/python/divmod-function-with-example.aspx

python中divmod

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值