Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to take a date from the user?

How would I go about designing a Python program which takes in a date from the user, a date that looks like this 3/13/17, and turns it into a date which looks like this 2017.3.13?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can split the string by using the str.split method like this:

s = "3/13/17"
month, day, year = s.split("/")
print(f"20{year}.{month}.{day}")

Python will automatically assign the splitted values to the variables month, day, and year

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading