python中weekday_Python calendar firstweekday()用法及代码示例

日历模块允许输出类似于程序的日历,并提供与日历相关的其他有用功能。 “日历”模块中定义的函数和类使用理想化的日历,当前的公历日历在两个方向上都无限期扩展。

在Python中,calendar.firstweekday()是日历模块中提供的用于简单文本日历的功能。

firstweekday()方法用于获取每周开始的工作日的当前设置。

用法: firstweekday()

参数: no parameter

返回: None

代码1:

# Python program to explain working of firstweekday() method

# importing calendar module

import calendar

# default firstweekday

print("Default First weekday is - ", calendar.firstweekday())

# setting 2nd day as firstweekday

calendar.setfirstweekday(2)

# print firstweekday

print("First weekday after modification is - ", calendar.firstweekday())

输出:

Default First weekday is - 6

First weekday after modification is - 2

代码2:用prmonth()方法解释firstweekday()方法的用法

# Python code to demonstrate the working of

# firstweekday() with help of prmonth() method

# importing calendar module for calendar operations

import calendar

# using prmonth() to print calendar of 1997

print ("The 4th month of 1997 is:")

calendar.prmonth(1997, 4, 2, 1)

# using setfirstweekday() to set first week day number

calendar.setfirstweekday(4)

print("First weekday after modification is - ",

calendar.firstweekday())

输出:

The 4th month of 1997 is:

April 1997

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

First weekday after modification is - 4

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值