Printing the result of datetime directly?


#1

Why is it necessary to store datetime.now in a variable before printing it, ie

print datetime.now()

#2

There is no variable there...


#3

It does return a value that gets stored in a variable, so it seems like you should be able to print the value directly. Other languages will allow this, so I'm curious why python doesn't.


#4

I'm still not seeing this 'variable' you're talking about.

You are calling datetime.now() which is a method/function call.

Aren't you printing it directly?


#5

In the lesson code, we have

now = datetime.now()
print now

now is the variable I meant, I should have been clearer. So it seems like you should be able to omit the assignment statement and just write

print datetime.now()

and get the same output.

The examples on this page suggest that you can directly print the value that a function returns, but it also says

 "Print is for people. Remember that slogan. Printing has no effect on the ongoing
 execution of a program. It doesn’t assign a value to a variable. It doesn’t return a
 value from a function call."

So I'm still confused.


#6

You can print it as you've shown, but you print it this way in the exercise:

now = datetime.now()
print now

Because you are later going to access datetime's internal methods in the next exercise.