hello everybody and welcome to the video on triple quoted strings this is chapter two section five of the book so we talked about uh strings and we talked about using either single quotes or double quotes with the string and we can do that we can create a string using the standard sort of double quotes or we can create a string using single quotes but one of the things that we can do is we can actually start and end a string with three quotes in a row so that's three double quotes as we see here or three single quotes as we see there so the style guide suggests that we can use these triple quoted strings for either multi-line strings so if we have a string that's going to run multiple lines a string that contains either single or double or both ideally double quotes right because if you have a string that contains a single quote like an apostrophe you can double quote that string and if you have a string that has double quotes then you can single quote that string but if you have a string that has both single and double quotes then you can triple quote the string and doc strings which are actually used for documentation so that's another thing we can use triple quoted strings for um we've seen multi-line strings before and we know how to do them but we can also do multi-line strings using triple quotes and here's two examples of that the first example which we see on the left is a code that i wrote in python and in spider in that sort of left terminal this is a multi-line string and notice i have the three quotes at the beginning and the end and this is the output that i get this is a multi-line string if i indent here on line 13 if i indent this then the corresponding second line will be indented as well and you can try that out and see what that looks like on the right hand side um this is what i did in sort of that lower right pane of spider where i put my print statement as soon as i started the triple quoted string and i hit enter on the next line it automatically put this stuff and it that's just a reminder to tell me that i'm actually continuing along the original string one of the things that we can do in our in our triple quoted string is we can include other quotes so in this case i have a single quote here i have a double quote there so i can triple quote the entire string and that gets me both the single and the double quote printed out without any escape characters likewise um for including escape sequences um i can still include the escape sequences in triple quoted strings but i don't have to escape either the single quote or the double quote that becomes completely unnecessary but if i need to put in a slash n to start a new line as i've done there then that's completely reasonable and doable in a triple quoted string now one of the things the triple quoted strings can be used for is what we call doc strings and doc strings are actually documentation for a function that you're writing in python when the user runs the help function um on the function that you've written then the docs string is returned as documentation for your code and we can see that in python when we hover over particular or we start typing for particular functions so for example let me just um pop over here into spider if i start out with a print statement here if i go print that stuff that pops up there is actually the doc string that is uh helping me in terms of telling me the documentation that i need to know about my print statement likewise if i were to try to do the sum of something it would give me some information about that so this these pop-up things are part of the help which uh which helps us figure out what's going on in the code so that's something that we probably want to keep in mind as well something that we're not going to be using now but you can pack away that tiny tidbit of information for later one additional note that i wanted to talk about because we're talking about quoted strings and single quotes and double quotes and in particular um i want to talk about stylized quotes if you look carefully you'll notice that the quote marks on the slides are all stylized and what i mean by stylized is if you take a look in there and look at those quotes you can see how this quote here uh those two are not actually the same the opening one and the closing one are different just like here the opening one and the closing one are actually slightly different these are what we call stylized quotes and we can see this over here even in the word open that's even more stylized quote right which is a bit of an issue so if you try and copy and paste these quote marks into either jupiter labs or into spider or into any other text editor they won't work and the reason why they won't work is because they actually appear in a different spot in the ascii table because they're not actually recognized as quotes so if you um consider for example back to when we talked about data encoding we talked about the ascii table well the ascii table stores a whole bunch of different characters and it has multiple different types of quotes and if you consider the fact that there's multiple different types of quotes out there then you realize that python doesn't necessarily recognize all of them it only recognizes certain ones so if i say print test this looks like a perfectly valid piece of code and it looks like it should work but the reason that it doesn't work is because the quote here the quote that we see here let's pick a different color here the quote that we see here is actually a stylized quote and it's not something that python recognizes and that's actually a bit of an issue because it doesn't it's a quote it looks like a quote to us everything looks good but the error that we're going to get is invalid character and identifier it doesn't understand that that's a double quote and that is actually a bit of an issue for us because we want it to know that it's a double quote now if i were to go over and take a look at what it looks like in spider itself and it's kind of hard because i can't really zoom i can't really zoom that into the point i think where you'll actually be able to see the difference but let me try anyway because there's no harm in trying if i zoom in enough there you'll see that that particular quote right those quotes at the beginning and the end are pretty much identical right they are very much a just the regular sort of quotes now if i wander out there and try to find let me see if i can find an example of a slide so with quotes in it so if i were to copy these two quotes off of that slide deck and i were to put those into python into uh spider you can see how they look different right they are definitely not the same quote and spider is smart enough to realize this it actually puts an x there and says that it's an invalid character and it's telling me it's actually telling me what the character is invalid character u plus 201c um so it's giving me that error but but also it's the wrong color right so with the color coding i know that um that's actually not part of a string so people some students will often cut and paste stuff from a website or they'll cut and paste stuff from a slide deck and it won't work and the reason that it won't work is simply because the fact that's not a proper quote that's why we are so stuck on using very particular fonts on websites so that when you cut and paste they cut and paste over properly so i just wanted to throw that out there because i think that that's really important to understand is that when we're doing strings like this and we're dealing with quotes that not all quotes are the same and that's the end of this particular slide deck thanks for watching