列表方法
# temp = input("请输入年月日(格式如2000年02月08日或2000.02.08):")# temp = "2000年02月08日"
temp = '2000.02.08'
temp = list(temp)
print(temp)
year = ''
month = ''
day = ''
feature = ''
for each in temp:
feature = temp.pop(0)
if(feature != '年')or(feature != '.'):
year += feature
else:
break
feature = ''
for each in temp:
feature = temp.pop(0)
if(feature != '月')or(feature!='.'):
month += feature
else:
break
for each in temp:
feature = temp.pop(0)
if(feature.isdigit()):
day += feature
print(feature)
else:
break
print(year)
print(month)
print(day)
print(temp)
有大佬能告诉我为什么“.”会分离到month和year里,而且temp里的最后一个元素8还提取不出来{:10_266:} 本帖最后由 jackz007 于 2021-3-17 22:01 编辑
temp = '2000.02.08'
year , month , day = map(int , temp . split('.'))
print(year)
print(month)
print(day)
jackz007 发表于 2021-3-17 21:59
人麻了,我竟然没想到用切片{:10_266:}
页:
[1]