fmod()函数是Python中的标准数学库函数之一,用于计算指定给定参数的模块。

用法: math.fmod( x, y )

参数:

x任何有效数字(正数或负数)。

y任何有效数字(正数或负数)。

返回:在计算给定参数x和y的模块后,返回浮点数值。

范例1:

# Python3 program to demonstrate fmod() function

import math

# Tuple Declaration

Tup = (15, 22, -2, -40 )

# List Declaration

Lis = [-89, 38, -39, 16]

# modulus of +ve integer number

print(math.fmod(4, 5))

print(math.fmod(43.50, 4.5))

# modulus of -ve integer number

print(math.fmod(-17, 5))

print('%.2f' %math.fmod(-10, 4.78))

# modulus of tuple item

print("\nModulus of tuple items:")

print(math.fmod(Tup[2], 5))

print(math.fmod(Tup[2], -6))

# modulus of list item

print("\nModulus of list items:")

print(math.fmod(Lis[3], 4))

print(math.fmod(Lis[0], -15))

输出:

4.0

3.0

-2.0

-0.44

Modulus of tuple items:

-2.0

-2.0

Modulus of list items:

0.0

-14.0

范例2:ValueError和TypeError

如果x和y参数均为零,则fmod()函数将输出返回为ValueError。

如果y参数(第二个参数)为零,则fmod()函数将输出返回为ValueError。

如果x值或y值不是数字,则fmod()函数将返回TypeError。

# Python3 program to demonstrate

# errors in fmod() function

import math

# will give ValueError

print(math.fmod(0, 0))

print(math.fmod(2, 0))

# it will give TypeError

print(math.fmod('2', 3))

输出:

ValueError:math domain error

ValueError:math domain error

TypeError:a float is required

python fmod函数_Python fmod()用法及代码示例相关推荐

  1. python iteritems函数_Python six.iteritems方法代码示例

    本文整理汇总了Python中sklearn.externals.six.iteritems方法的典型用法代码示例.如果您正苦于以下问题:Python six.iteritems方法的具体用法?Pyth ...

  2. python label函数_Python pyplot.clabel方法代码示例

    本文整理汇总了Python中matplotlib.pyplot.clabel方法的典型用法代码示例.如果您正苦于以下问题:Python pyplot.clabel方法的具体用法?Python pypl ...

  3. python中strftime函数_Python strftime()用法及代码示例

    在Python中,日期和时间不是其自身的数据类型,而是名为 strftime()函数用于将日期和时间对象转换为其字符串表示形式.它需要一个或多个格式化代码输入,并返回字符串表示形式. 用法: strf ...

  4. python并集符号_Python Union()用法及代码示例

    两个给定集合的并集是包含两个集合的所有元素的最小集合.两个给定集合A和B的并集是一个由A的所有元素和B的所有元素组成的集合,这样就不会重复任何元素. 表示集合并集的符号是" U". ...

  5. python beep函数_Python winsound.Beep方法代码示例

    # 需要导入模块: import winsound [as 别名] # 或者: from winsound import Beep [as 别名] def Run(self): if not self ...

  6. python tkinter insert函数_Python tkinter.INSERT属性代码示例

    本文整理汇总了Python中tkinter.INSERT属性的典型用法代码示例.如果您正苦于以下问题:Python tkinter.INSERT属性的具体用法?Python tkinter.INSER ...

  7. python html模板_Python html.format_html方法代码示例

    本文整理汇总了Python中django.utils.html.format_html方法的典型用法代码示例.如果您正苦于以下问题:Python html.format_html方法的具体用法?Pyt ...

  8. python session模块_Python backend.set_session方法代码示例

    本文整理汇总了Python中keras.backend.set_session方法的典型用法代码示例.如果您正苦于以下问题:Python backend.set_session方法的具体用法?Pyth ...

  9. python color属性_Python turtle.color方法代码示例

    本文整理汇总了Python中turtle.color方法的典型用法代码示例.如果您正苦于以下问题:Python turtle.color方法的具体用法?Python turtle.color怎么用?P ...

最新文章

  1. 初识java类的接口实现
  2. 2048c语言程序,C语言实现2048小游戏
  3. python给图片添加字符
  4. SpringBoot整合Minio 项目中使用自己文件存储服务器
  5. secureCRT配置ssh -x
  6. jfinal出现sql injection violation, multi-statement not allow : select count(*) select a.name,
  7. 【安卓开发】Webview简单使用
  8. C语言数据结构编程实列,数据结构C语言实现----栈的实例
  9. excel方格子插件_转载 | 18个Word/Excel/PPT插件整理
  10. Fedora16 安装相关
  11. java的运行环境是什么_Java运行环境是什么
  12. 语音处理基础:预加重、分帧、帧移、加窗、傅里叶变换
  13. git add未commit reset恢复文件
  14. 038-拯救大兵瑞恩之 TiDB 如何在 TiKV 损坏的情况下恢复
  15. neuq oj 1034: C基础-求同存异 C++
  16. Android AssetManager 1
  17. 在 web of science上到导出txt文件
  18. python设置背景颜色(mac)_配置PyCharm(背景色+字体大小+解释器选择)
  19. 弹性云服务器的稳定可靠性,弹性云服务器的稳定可靠性
  20. hbck源码系列(四)--表的完整性检查和修复Check

热门文章

  1. 字节跳动、学而思纷纷进场,线上自习室2021更火了?
  2. c# jobject 的数据结构的解析
  3. 2021化州市高考成绩查询,2021年化州市高考状元名单资料,今年化州市高考状元多少分...
  4. Let's make 16 games in C++(十六):Volleyball
  5. html5 a标签去下划线,css中如何去掉a标签的下划线?
  6. 系统拆分之按业务进行拆分
  7. 【牛腩】LinkButton
  8. git 命令怎么删除远程分支
  9. 数据库多对多的通俗理解
  10. java笛卡尔积算法_Java 笛卡尔积算法的简单实现