如何区分字符串中的日期,月份和年份?(How to distinguish between date, month and year in the string?)

编程入门 行业动态 更新时间:2024-10-24 14:20:05
如何区分字符串中的日期,月份和年份?(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 = 1999

strip 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

更多推荐

本文发布于:2023-07-25 19:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1265225.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   年份   日期   distinguish   string

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!