The datetime object you assign on line 4 is not a tuple. You don't extract the elements from it by numeric index like a list or tuple.
Instead you either access the attributes of the object (like .year) to pull the individual bits, or you use strftime() to format it it how you want.
Instead you either access the attributes of the object (like .year) to pull the individual bits, or you use strftime() to format it it how you want.
from datetime import datetime d = datetime.strptime('8 Aug 2015', "%d %b %Y") print(f"The returned item is of type {type(d)}") print(d.year) # extracts year as an int print(d.strftime("%Y")) # extracts year as a string
Output:The returned item is of type <class 'datetime.datetime'>
2015
2015