WHAT I DID TODAY:
Today I finished the 'Date and Time' unit in the Python 2 course. There were only 6 lessons and it was pretty simple. It was just on how to write the date/time in different formats.
|
THE COURSE IS NOW 15% COMPLETE |
And of course after the lessons, there was a review of everything I learned. I was told to add the time and date together.
|
ALL THE CODE I LEARNED TODAY |
WHAT I LEARNED:
Since this unit was very specific, I mainly just learned how to make the computer generate the current time/date by using code and how to set it up in different formats.
- The first thing I learned was the 'base' of writing time/date code. Writing datetime.now() automatically gives you the current date and time. After that just use the classic print command to print it out.
|
EVERYTIME YOU USE THE DATE AND TIME MAKE SURE TO PRINT 'from datetime import datetime' at the top |
- The second thing I learned was that if you didn't want something specifically like for example the seconds, you can exclude that by writing print now.month , after doing that though, the program will only print out what you listed under the now = datetime.now() Here's a picture that shows what I mean.
|
ONLY MONTH AND DAY SHOWS UP
|
- The third thing I learned was changing the formats. As you can see from the very first example image, it automatically prints out the date and time in this format:
But to change the format to normal, like mm/dd/yyyy, you just need to write print "%02d/%02d/%04d" the / represents the split between mm/dd/yyyy. If you wanted to change it to : or - you can. And the 02 and 04 represents the number of digits, as month and day requires 2 digits while year is 4 digits.
|
PICTURE SHOWING WHAT I EXPLAINED ABOVE |
Another thing to note is that after "%02d/%02d/%04d" there is a % sign. In my other post I explained before that the code after the % corresponds to the order the variables that are listed after it.
WHAT I WILL BE DOING TOMORROW / NEXT TIME:
Next time I will be working on the next Unit in the course, which is 'Conditionals & Control Flow' There is actually 15 lessons in this unit so I'm sure I wouldn't be able to go through it all. I'll probably go through half and then do the other half next time.
|
DESCRIPTION OF NEXT UNIT |
No comments:
Post a Comment