Prior to doing these labs for python I have already learned how to code in JavaScript, so some of these concepts are very familiar to me but in a different syntax. This was new to me as you can print several values into a single string.

In this screenshot they used a library in python named datetime so we would be able to format and print the date and time.


In this screenshot we assign the variable “now” to datetime.now(). This function allows use to retrieve the current date and time, then we use print to log the value of “now”.


We can extract information from this library by simply calling which information we would want. If we wanted the year, we called the variable “now” and add .year to the end of it. I printed out the year, month and date by doing print now.year, print now.month, and print now.day in that perspective order.


Rather than printing out a whole string in one line we can use string substitution to place the values where we would want it to be. We first would write the % operator would fill the %s placeholders in the string right next to it. So for an example ” print ‘Hello %s and %s!’ % (‘world’, ‘aliens’); ” this line of code would print out the string “Hello world and aliens!”. So in this project we separated the month, day and year with “/” to format the month, day and year. So the line of code would look like ” print ‘%s/%s/%s’ % (now.month, now.day, now.year); “.


Here, we do the same for hour, minute and second. But this time we replace “/” with “:” because we are dealing with time. So the line of code would look like ” print ‘%s:%s:%s’ % (now.hour, now.minute, now.second); “.


Finally, we combine the two lines of code into one. Firstly, I took ‘%s:%s:%s’ from line 5 and inserted it in the string with “%s/%s/%s”. Then I inserted “now.hour, now.minute, now.second” before the variables “now.month, now.day, and now.year”. Then it would finally print the date and time that I had, which was “9/17/2017 19:54:28”.