Is it really necessary to create a now variable to get hour, day, month etc.?


It seems it is not really necessary to use a variable now. Without using such a variable, it still works. Here is my code. Is there anyone who could explain why it says us to create such a variable.

from datetime import datetime

print '%s:%s:%s' % (now.hour, now.minute, now.second)


it throws an error:

maybe your browser is sending cached data, which might cause it to look like its working without the now variable


very probable.
any tips for not having this situation again?


having an unnamed variable (now), should raise red flags that something is off. refresh the page, run the code locally on your machine or sites like repl for verification


you need to otherwise it is considered undefined. But good question. :rofl:


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