Assigning datetime.datetime output to a variable, rather than to object

Screen Link:
https://app.dataquest.io/m/353/working-with-dates-and-times-in-python/5/using-strptime-to-parse-strings-as-dates

My Code:

import datetime as dt
#print(potus[0:])
#Start_date=0
date_format='%m/%d/%y %H:%M'
for row in potus[0:4]:
    appt_start_date=row[2]
    print(appt_start_date)
    Start_date=dt.datetime.strptime(appt_start_date,date_format)
    print(Start_date)
    row[2]=Start_date
    print(row[2])
    
print(potus[0:3])

What I expected to happen:
I was hoping this code updates all the row[2] values in potus list with updated date format.

What actually happened:
when the potus list is updated it at row[2] it shows output as datetime.datetime(2015, 1, 6, 9, 30) instead of 2015-01-06 09:30:00.
When I tried to debug, and added print messages at every line, while the code executes, the variables looks right. However in the end when it updates the potus list, and when I print Potus list, it doesn’t get updated correctly.

Replace this line with the output/error
3 Likes

Hello @sri.medisetti, This will help.

Let me know if you still have any doubt. :slightly_smiling_face:

2 Likes

Yes, that is very helpful…As printing individual object was showing different values than printing the whole list, this confusion arises…

1 Like