Is datetime actually current?

#1 lesson
For lesson 2 on this topic, we import datetime from the datetime library, and store the current time in a variable “now”.

from datetime import datetime
now =
print now

Is the time stored in the variable the time it was when datetime was imported? Or is the datetime self-updating? Another way to phrase it is: If we wrote a forever loop, and forever printed, would it print the same time over and over (the time it was when we imported datetime) or would it change the time in order to reflect the current time?


every time you call the .now() method, the method will retrieve the current time (so it will update)


But if we consistently just printed the now variable, it wouldn’t update right? Because we’re not calling the .now() method, we’re just printing information already stored in a variable?


yes, exactly.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.