将2位数表达的年份,转换为用4位数表达:
print("将列表中的2位数年份转换为4位数年份")
lst=[88,89,90,00,99]
print(lst)
for index in range(len(lst)):
if len(str(lst[index]))==2:
lst[index] = 1900+int(lst[index])
elif len(str(lst[index]))==1:
lst[index] = 2000+int(lst[index])
print(lst)
lst = [88,89,90,00,99]
for index,value in enumerate(lst):
if len(str(value))==2:
lst[index]= 1900 + int(value)
else:
lst[index] = 2000 + int(value)
print(lst)

文章描述了如何使用Python脚本,通过for循环和enumerate函数,将列表中2位数的年份(如88,89等)转换为4位数(如1988,1989等),并将结果存储在同一个列表中。
1016

被折叠的 条评论
为什么被折叠?



