Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAnthony Grodowski
4,902 PointsDifference beetween ```.now()``` and ```.now```
I think I don't have a correct understanding on the difference between datetime.datetime.now
and datetime.datetime.now()
. Can someone clear that up for me?
1 Answer
Steven Parker
231,269 PointsWhen you call a method, you put parentheses after the method name. WIthout them, you are referencing the method without invoking it.
So the first example would return the resut of calling the method (which would be the current date and time), but the second one is a reference to the method itself.
Anthony Grodowski
4,902 PointsAnthony Grodowski
4,902 PointsThanks Steven! So what's the point of putting that in here:
if it's just referencing to the method and it doesn't return anything?
Steven Parker
231,269 PointsSteven Parker
231,269 PointsIt returns a reference to the method, which is assigned as the "default". So when a record is added without an explicit timestamp value, then the method will be called to fill the timestamp with the current date/time.