• 技术文章 >Python技术 >Python基础教程

    python教程实例:生成指定日期的日历

    宋雪维宋雪维2020-12-01 09:00:12原创3109

    如果和年纪稍长的人说起日历这个词,我想他们联想到更多的是纸质的台历或者挂历。这时的日历职责非常简单:显示日期,提醒重要日子的临近。从最早的纸张日历,现在已经衍生到电子版、网页版、手机版等等。通过使用日历,我们可以明确自己的时间本金,做好时间管理。今天小编就用python来生成一份指定日期的日历。

    代码:

    1

    2

    3

    4

    5

    6

    <span style="color: rgb(0, 0, 0); text-decoration: none;"># Filename : test.py

    # author by : </span><a style="color: rgb(0, 0, 0); text-decoration: none;" href="http://www.runoob.com"><span style="color: rgb(0, 0, 0);">www.runoob.com</span></a><br><span style="color: rgb(0, 0, 0); text-decoration: none;"># 引入日历模块

    import calendar<br># 输入指定年月

    yy = int(input("输入年份: "))

    mm = int(input("输入月份: "))<br># 显示日历

    print(calendar.month(yy,mm))</span><br>

    输出结果:

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    <p style="line-height: normal;">输入年份: 2020

     

    输入月份: 7

     

          May 2020

     

    Mo Tu We Th Fr Sa Su

     

           1  2  3  4  5

     

     6  7  8  9 10 11 12

     

    13 14 15 16 17 18 19

     

    20 21 22 23 24 25 26

     

    27 28 29 30 31<br></p>

    这样就能用python制作一份指定日期的日历了。大家如果有时间,也可以动手做一份日历哦~更多学习推荐:python学习网。

    专题推荐:python教程
    上一篇:如何在python中编写空函数? 下一篇:python入门之如何打开文件

    相关文章推荐

    • Python教程:巧用openpyxl为指定区域设置边框为粗匣框线• Python教程:pdfplumber提取pdf中的表格数据• Python教程:int()函数的用法解析

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网