Python中的取模运算方法
作者:爱买耳钉的阿喵阿汪 时间:2023-11-10 04:39:56
所谓取模运算,就是计算两个数相除之后的余数,符号是%。如a % b就是计算a除以b的余数。用数学语言来描述,就是如果存在整数n和m,其中0 <= m < b,使得a = n * b + m,那么a % b = a - n * b = m.
取模运算的两个操作数都必须是整数,可以是负整数,但是b不可以是0,因为被除数不能为0嘛。
当a和b中存在负整数时,首先计算|a|%|b|=c,然后a%b的符号与b一致。也就是说,如果b>0,则a%b=c;如果b<0,则a%b=-c
比如:
来源:https://blog.csdn.net/SharonLu1216/article/details/76774829
标签:Python,取模,运算
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
交互设计实用指南系列(10)—别让我思考
2010-03-01 12:50:00
使用selenium自动控制浏览器找不到Chromedriver问题
2023-02-02 01:32:33
![](https://img.aspxhome.com/file/2023/2/131932_0s.jpg)
python基础之错误和异常处理
2021-07-28 05:46:15
![](https://img.aspxhome.com/file/2023/3/65933_0s.png)
透明度设置
2009-12-12 18:51:00
Python机器学习NLP自然语言处理基本操作关键词
2023-11-09 05:51:31
![](https://img.aspxhome.com/file/2023/9/63549_0s.gif)
Python 实现递归法解决迷宫问题的示例代码
2021-01-31 08:14:23
![](https://img.aspxhome.com/file/2023/4/124204_0s.png)
python3+opencv生成不规则黑白mask实例
2023-10-06 11:01:25
![](https://img.aspxhome.com/file/2023/5/72995_0s.jpg)
Java生成日期时间存入Mysql数据库的实现方法
2024-01-13 03:49:08
![](https://img.aspxhome.com/file/2023/4/77344_0s.png)
解释FCKeditor样式的工作原理
2007-10-11 13:34:00
Springboot Mybatis-Plus数据库单元测试实战(三种方式)
2024-01-24 19:39:28
![](https://img.aspxhome.com/file/2023/8/120528_0s.png)
python实现视频压缩功能
2023-12-14 02:48:36
![](https://img.aspxhome.com/file/2023/0/90850_0s.png)
python任务调度实例分析
2021-06-30 12:42:57
ASP开发中有用的函数(function)集合(3)
2008-10-14 17:20:00
Google中秋logo被恶搞
2007-09-25 15:55:00
详解Go语言中关于包导入必学的 8 个知识点
2023-07-09 05:38:11
![](https://img.aspxhome.com/file/2023/9/87619_0s.png)
Python实现一个转存纯真IP数据库的脚本分享
2024-01-17 16:43:38
![](https://img.aspxhome.com/file/2023/8/103288_0s.jpg)
使用numpy对数组求平均时如何忽略nan值
2023-09-19 20:37:24
![](https://img.aspxhome.com/file/2023/7/97307_0s.png)
pytorch中fuse_modules源码解读
2023-09-15 20:58:01
![](https://img.aspxhome.com/file/2023/7/97347_0s.png)
javascript解锁前端密码框常见功能做法
2024-04-16 10:36:33
![](https://img.aspxhome.com/file/2023/0/136640_0s.png)
Python IDLE或shell中切换路径的操作
2022-06-03 18:05:32
![](https://img.aspxhome.com/file/2023/6/128186_0s.jpg)