Python计算已经过去多少个周末的方法
作者:Sephiroth 时间:2023-03-10 11:40:52
本文实例讲述了Python计算已经过去多少个周末的方法。分享给大家供大家参考。具体如下:
def weekends_between(d1,d2):
days_between = (d2-d1).days
weekends, leftover = divmod(days_between,7)
if leftover:
start_day = (d2-timedelta(leftover)).isoweekday()
end_day = start_day+leftover
if start_day<=6 and end_day>6:
weekends +=.5
if start_day<=7 and end_day>7:
weekends +=.5
return weekends
使用方法:
weekends_between(date(2004,10,1),date(2004,10,10))
希望本文所述对大家的Python程序设计有所帮助。
标签:Python,计算
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
解决Python中字符串和数字拼接报错的方法
2023-06-11 23:12:37
![](https://img.aspxhome.com/file/2023/4/128594_0s.jpg)
Python3导入自定义模块的三种方法详解
2021-06-05 18:49:27
![](https://img.aspxhome.com/file/2023/3/86533_0s.png)
TensorFlow MNIST手写数据集的实现方法
2022-12-19 19:45:02
SQL Server 2008网络协议深入理解
2024-01-17 02:42:34
让验证码友好一点
2007-10-20 13:45:00
![](https://img.aspxhome.com/file/UploadPic/200710/20/20071020135017833s.gif)
Python如何创建装饰器时保留函数元信息
2023-03-29 12:32:46
django Layui界面点击弹出对话框并请求逻辑生成分页的动态表格实例
2021-04-17 02:03:04
![](https://img.aspxhome.com/file/2023/2/89182_0s.jpg)
解析Python 偏函数用法全方位实现
2023-12-22 00:06:03
![](https://img.aspxhome.com/file/2023/3/83953_0s.jpg)
Mysqlslap MySQL压力测试工具 简单教程
2024-01-15 20:10:10
Python抓包程序mitmproxy安装和使用过程图解
2023-12-09 19:45:12
![](https://img.aspxhome.com/file/2023/9/66879_0s.png)
Golang函数这些神操作你知道哪些
2024-04-26 17:22:15
MySQL 整表加密解决方案 keyring_file详解
2024-01-18 07:50:31
mdf文件和ldf文件导入到sql server 2005实现语句
2024-01-21 14:38:07
Python 含参构造函数实例详解
2023-02-06 13:16:48
ORM框架之Dapper简介和性能测试
2024-05-03 15:30:44
ASP使用fso遍历文件及文件夹列出文件名
2008-10-27 19:32:00
update.where无索引导致MySQL死锁问题解决
2024-01-28 01:21:25
![](https://img.aspxhome.com/file/2023/4/112894_0s.png)
Python批量重命名同一文件夹下文件的方法
2021-04-03 08:59:44
php之Aes加密案例讲解
2023-06-11 12:59:12
![](https://img.aspxhome.com/file/2023/7/55557_0s.png)
Oracle 处理json数据的方法
2024-01-16 15:11:15
![](https://img.aspxhome.com/file/2023/2/65262_0s.png)