如何区分字符串中的日期,月份和年份?(How to distinguish between date, month and year in the string?)
我有一个问题:如何使用“strip”功能来分割像“24.02.1999”这样的日期? 输出结果应该是'24','02','1999'。
你能帮忙解决这个问题吗?
I have a question: How to use "strip" function to slice a date like "24.02.1999"? The output should be like this '24', '02', '1999'.
Can you help to solve this?
最满意答案
strip用于删除字符。 你的意思是split 。 对于你的代码,
date = input('Enter date in the format (DD.MM.YY) : ') dd, mm, yyyy = date.strip().split('.') print('day = ',dd) print('month = ',mm) print('year = ',yyyy)输出:
Enter date in the format (DD.MM.YY) : 24.02.1999 day = 24 month = 02 year = 1999strip is used to remove the characters. What you meant is split. For your code,
date = input('Enter date in the format (DD.MM.YY) : ') dd, mm, yyyy = date.strip().split('.') print('day = ',dd) print('month = ',mm) print('year = ',yyyy)Output:
Enter date in the format (DD.MM.YY) : 24.02.1999 day = 24 month = 02 year = 1999更多推荐
发布评论