Python Grand finale


#1

In this exercise, I first wrote the code

‘%02d/%02d/%04d’ ‘%02d:%02d:%02d’ % (now.month, now.day, now.year, now.hour, now.minute, now.second)

though is prints on in the console, the year and hour was joined. then I tried this

print ‘%s/%s/%s %s:%s:%s’ % (now.month, now.day, now.year, now.hour, now.minute, now.second)

and it worked.

My Question is, why did the second code work, since in the lessons, I gathered that we need to use %02d placeholders…

What was the technical difference.


#2

%s refers to a string whereas %02d refers to a 2-digit number. My guess is now.month returns a string not a digit so in the first one it didn’t match properly.

There’s a little more information here


#3

I am a little confused here because all the values of the variables are in numbers… isn’t that the digits you talk about?