Hi,
I’m happy to have joined the forum and to have found this book/course, it’s really structured in a way that works well with the way that I learn.
I have no previous experience with other programming languages and decided to learn python because I have a couple of boring tasks that eat up my time at work which I’d like to see automated. I chose Python because it seemed like the easiest language to start off with, specially after my brief encounter with a few chapters of a C++ introduction book that I decided to put aside for the moment.
Anyways moving on to the question that I had regarding Exercise 9 of Learning Python The Hard Way.
I was busy breaking my own code in order to then fix it.
This is what my code looks like before I start breaking it:
Here's some new strange stuff, remember type it exactly
days ="Mon Tue Wed Thu Fri Sat Sun" # creats variable called days and makes value = string
months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug" #\N creats variable called months and makes value = string. The \n tells
#python we want each month stored as a value in its own line
print("Here are the days: ", days) #prints out a string plus value of variable days
print("Here are the months: ",months) #print out a string plus value of variable months
print("""
There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.
""") # We are printing out a string and making use of the 3 """ in order to allow
#us to continue typing on a different line and use a combination of symbols like "" or '' without
# it being considered the delimiter to end the string.
I tried ading more “”" on line 14 and predicted that It would simply print out all the characters after the third " all the way up to a maximum of “”" (since that is the delimiter used to end the string). Even so I decided that I wanted to use the “”"" delimiter but start by printing a string of “”".
An easy way to accomplish this was:
print(('"""\n')+"""
There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.
""") # We are printing out a string and making use of the 3 """ "in order to allow
#us to continue typing on a different line and use a combination of symbols like "" or '' without
# it being considered the delimiter to end the string.
I then did the following, initially thinking that somehow that the 6x" would somehow print out the middle 3 “”".
print((""""""""") + """
There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.
""") # We are printing out a string and making use of the 3 """ "in order to allow
#us to continue typing on a different line and use a combination of symbols like "" or '' without
# it being considered the delimiter to end the string.
I realised that this didn’t make much sense because well i started the delimiter as “”" and it followed with another set of “”", essentially meaning empty string. What I would like to understand is how python interprets the next set of “”" which are then closed off by the bracket. In terms of output nothing happens and I could have simply left the last “”" out. How does it discard the remaining three and not deliver an error.
If i print out the 3 quotes by themselves I get a syntax error, why is it different since it is inside a bracket?