[英]Save Weekday into variable as string and if equal print 'something' python
import time
import datetime
date = time.strftime("%A")
week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
weekend = ["Saturday", "Sunday"];
if weekend == date:
print ("Today is: " + date)
/ I want to make schedule. / 我要安排时间表。 So when a day is equal with one of my days saved in variable it will print out my schedule for that date. 因此,当某天等于我的某一天保存在变量中时,它将打印出该日期的时间表。 As you can see I dont have the schedules yet. 如您所见,我还没有时间表。 I just need ot know how to save current day as string / 我只需要知道如何将当前日期另存为字符串 /
You want to check if date
is in
either of the two collections, week
or weekend
. 您要检查date
是否in
两个集合中, week
或weekend
。 Like: 喜欢:
if date in week: # or weekend
print('Weekday')
Use set
s for more efficient checking, like: 使用set
进行更有效的检查,例如:
weekend = set(["Saturday", "Sunday"])
Also, no semicolons to end a statement. 另外,也没有分号来结束语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.