For this practical, we'll be going over the basics of creating and manipulating strings in Python. So, to begin with, let's just define a new string, which we'll call seq. We can do this by just using single quotes, like that. We can also define a string using double quotes. Just like that. So these two lines do the exact same thing. Now let's suppose we want to get a character from the string. We can do this using the bracket notation. So, this will give us the character at index one in our string. There is that it gives us C, which is actually the second character in the string. It's important to remember that strings in Python are zero indexed. That means that the first character in the string is index zero, and the second character is index one, and so on. If we want to get the length of our string, we could just type length. Just like that. And as we would expect, our string is four characters long. We can define an empty string by just putting two quotes with nothing in-between them. And if we get the length of an empty string, that's length zero, just like we would expect. Now let's concatenate two strings. So I'm going to define two strings. I can concatenate these by just using a plus sign. You can see that python has added these two strings into a single new string. We can also concatenate strings using the join function. So to do this, I'm going to start by creating a list of strings. If I want to concatenate these strings with nothing in between them, I first put two single quotes for an empty string and then .join, and then I put the list. So this will join the list using the separator that's before the period. So in this case, it's an empty string, so we'll concatenate them just like that. If we wanted to add them with commas in between them, we could put a comma in there, and now it gives us that. Now let's try creating a random string of DNA sequences. So in order to do this I'm going to use the random module in Python. So I'm going to do import random. And then I can use random.choice to choose a random character. I'm going to give it a string of characters to choose from. So I'm going to give it the four nucleotides. And if I run that it gives me a randomly chosen nucleotide from that string. >> And if you run that again and again, you're going to get different ones, right? >> Yeah, it'll give me different nucleotides every time. If I want it to give me a predetermined order so it will give me the same behavior every time, I can seed it by doing something like random.seed. And then put an integer in there. And now it should give me, every time I run it, it should give me the same behavior. So in this case it will give me G every time. So now let's use this random.choice to generate a longer string of nucleotides. So to do this I'm going to first create an empty sequence. And I'm just going to repeatedly add random nucleotides to it. So I'm going to create a loop, and I'm going to loop, I'll go ten times. So it will be a string of length ten. And then each time I go through the loop I want to take my string and append onto it. I randomly chose a nucleotide. And if I run this, you see I get a string of nucleotides. And every time I run it, it will give me a different random string. Now in your loop, you used for _ in range. Can you just say something about what the underscore means? >> Yeah, so in this case I don't care what index in the iteration I'm at. So I use an underscore to indicate that I don't want to save that number to a variable. If I cared about my index I could do something like for i in range ten. And then I would loop from zero up to nine. In this case since I'm not using i, I can just replace it with an underscore. Another way to generate a random sequence is using join. So, I'm going to do like this, empty string.join which we saw above and then I'm going to give it a set, random.choice for_in range. So you probably recognize most of these elements from the block above. In this case, we just combine them into a single line to create a list of randomly chosen nucleotides and then join them into a string. Print that out just to verify that it worked and there's our random stream. So we already talked about getting a specific character from a stream. We can also get substreams using a colon. So say I want to get just a range of characters if I do 1:3 that will give me the range of characters from index one up to, but not including, index three. So, this is referring to the string I just generated and it's giving me the two T's there. We can get a prefix by just not putting a number before the first colon. So if I just do :3, this will give me everything from the beginning of the string up to but not including index three. So, it gives me GTT. >> So that would be the same as if you had put zero colon three inside the square. >> Right. So If I do 0:3 it gives me the exact same thing. And similarly we can get a suffix by just not putting a character after the seven. And that gives us CAG which is at the end. And this would be identical if we put from 7 up to the length of the sequence. Another way we can get a suffix is actually using negative indices. So if we put a negative index in brackets, it will give us, it will count backwards from the end of the string to get that. So for our sequence above, if I do sequence -3, it gives me C. Which, you'll notice, is the third character from the end of that string. And similarly I can do sequence from -3: and then, just leave the end point blank, and that will give me the last three characters of the string, so that's the suffix of length three of the string.