实现列表的遍历查询:
fi = open("PY301-vacations.csv","r")
ls = []
for line in fi:
ls.append(line.strip("\n").split(","))
s = input("请输入节假日序号:").split(" ")
while True:
for i in s:
for line in ls:
if i == line[0]:
print("{}({})假期是{}月{}日至{}月{}日之间".format(line[1],line[0],line[2][0]+line[2][1],line[2][2]+line[2][3],line[3][0]+line[3][1],line[3][2]+line[3][3]))
s = input("请输入节假日序号:").split(" ")
Python strip()方法
原型:str.strip([chars]);
参数:
- chars -- 移除字符串头尾指定的字符序列。
作用:返回移除字符串头尾指定的字符生成的新字符串。
Python split()方法
原型:str.split(str="", num=string.count(str)).
参数:
- str -- 分隔符,默认为所有的空字符,包括空格、换行(\n)、制表符(\t)等。
- num -- 分割次数。默认为 -1, 即分隔所有。
作用:返回分割后的字符串列表。