Is datetime actually current?


#1

datetime.now() 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 = 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 datetime.now(), 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?


#2

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


#3

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?


#4

yes, exactly.


#5

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