Python: Date and Time

Create a variable called now and store the result of in it.
Then, print the value of now.

I’m just starting Python and I’m stuck; I don’t understand what the intrusctions are asking of me. Please help!

1 Like

Some assigning and printing:

total = sum([2, 7])
print total

Thank you, but I already figured it out. :slight_smile:

It wasn’t asking for a total

The interpolating that is done in the datetime section seems to not work in python update 3.5.1. does anyone know the new method for this below

print ("%s/%s/%s") % (now.month,, now.year)

this same code gives a syntax error in pythons 3.5.1 IDLE

That’s valid syntax in both Python2 and Python3.
The use of parentheses around the string literal is questionable though, and is interpreted differently in Python2 and Python3 as a result of that the print statement was removed in Python3.

This expression: (5) has redundant parentheses in it. It should just be: 5
In this expression, the parentheses form the call operator: add_one(5)

1 Like

Absolutely wonderful. The error I had is what you get when you spend 30 hours working with the old program, reading a book on 2.5, then jumping to code academy and updating to 3.5. lol. Fixed the syntax, I did not know print was no longer necessary which is a cool time saver. The parentheses I thought was required for everything in 3.5, I must have misread something on pythons site. It worked perfectly with:

“%s/%s/%s” % (now.month,, now.year)

You saved me from a stroke lol Thank you so much. I absolutely love learning this language and I spent thirty minutes changing the code over and over again in IDLE attempting to correct it. I wasn’t giving up.

I suppose it’s true that if something stops existing it’ll also stop being necessary, but you’ll still need write code that says “I want this to be printed” which is done by calling the print function.

Within python 3.5.1 I will still need to write code calling for it to be printed? Or are you speaking to other languages I will be learning?

If you want something to be printed, then you’ll need to call the print function:

print('bob is purple')

or in Python2, use the print statement:

print 'bob is purple'

the following is equivalent to a comment, it has no effect:

'bob is purple'

I’m kind of confused. In your first reply you said the parentheses was not necessary for a print function and you also stated that in python 3 print was removed. It looks like you are saying now that parentheses as in your Bob example, are still necessary with strings and that print is still needed in the latest version of python. Sorry if I’m a little confused, if you could clarify I would appreciate it. Thank you.

I said no such thing. Parentheses are the operator for calling functions.

The print statement was removed. Yes. Which doesn’t mean that things print themselves, it just means you have to use something else. The function with the same name.

Your variable should look like this:

now =

though it may seem weird. I just got past that lesson!:slightly_smiling:


You stated that," I already figured it out." I’m having the same issue with datetime lesson. Please explain what is meant by
“Create a variable called now and store the result of in it.
Then, print the value of now.?”

hey can you please tell me how you did it iam just starting this and i feel like iam lost in space

from datetime import datetime
now = 4
now =
print now

thanks mate :wink: it did work for me but i suppose declaring now=4 is not actually necessary.

in the grand finale of the date time lesson I am completely stumped on what is going wrong I have printed the date and time in the correct format each time and even copy pasted the code provided to me when i got too frustrated and the site still told me that the format was wrong, please help.