Python divmod 函数

您所在的位置:网站首页 python中的divmod函数 Python divmod 函数

Python divmod 函数

2022-05-27 01:05| 来源: 网络整理| 查看: 265

目录

一.divmod 函数介绍 二.divmod 函数使用 三.猜你喜欢

零基础 Python 学习路线推荐 : Python 学习目录 >> Python 基础入门

一.divmod 函数介绍

divmod 函数也是 Python 的内置函数,它是把除数和余数运算结果结合起来,返回一个包含商和余数的元组 tuple (a // b, a % b)

''' 参数: x,y都是数字,可以是整形也可以是浮点数,x 是分子,y 是分母; 返回值:返回一个元组(x//y,x%y); ''' divmod(x, y) 二.divmod 函数使用 # !usr/bin/env python # -*- coding:utf-8 _*- """ @Author:猿说编程 @Blog(个人博客地址): www.codersrc.com @File:Python divmod函数.py @Time:2021/04/04 11:00 @Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累! """ print("{}".format(type(divmod(9,6)))) print("{}".format(divmod(9,6))) print("{}".format(type(divmod(9.2,6.6)))) print("{}".format(divmod(9.2,6.6))) ''' 输出结果: (1, 3) (1.0, 2.5999999999999996) '''

注意:divmod 函数只能接受整数 int 或浮点数类型 float 参数,不能使用字符串 string , 否则会报错!

三.猜你喜欢 Python 字符串/列表/元组/字典之间的相互转换 Python 局部变量和全局变量 Python type 函数和 isinstance 函数区别 Python is 和 == 区别 Python 可变数据类型和不可变数据类型 Python 浅拷贝和深拷贝 Python 递归函数 Python sys 模块 Python 列表 list Python 元组 tuple Python 字典 dict Python 条件推导式 Python 列表推导式 Python 字典推导式 Python 函数声明和调用 Python 不定长参数 *argc/**kargcs

未经允许不得转载:猿说编程 » Python divmod 函数

本文由博客 - 猿说编程 猿说编程 发布!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3