Advertisement
This is comment for paste
CodefessReply-month
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- instead of all that unnecessary code just make it shorter with this
- import calendar
- def get_month(date_string):
- # Split the date string into a list of three strings, representing the day, month, and year
- try:
- day, month, year = date_string.split("-")
- # Convert the month string to an integer
- month_number = int(month)
- except (ValueError, TypeError):
- # Handle invalid input
- return None, None, None
- # Get the month name from the calendar module
- month_name = calendar.month_name[month_number]
- return int(day), month_name, int(year)
- # Test the function with the input string '26 - 01 - 2022'
- print(get_month("26-01-2022")) # Output: (26, "January", 2022)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement