 Welcome back everyone. Today we're going to talk about importing additional code into your Python scripts. So by default, Python understands a certain number of commands and these are built-in commands. So you've already seen some of them. For example, assigning a variable. So we assign variables like x equals 1. Python would understand what that means. It also understands the statement like if, you know, x less than y, then Python understands those kind of things. You've also seen loops. You've seen function definitions. Yeah, so there's a bunch of things that by default Python understands. However, we want to make sure that our code or our scripts are as small as possible. And there's a bunch of functionality that exists that people have already written or additional functionality in Python that's not turned on or included by default because we don't always need all of that functionality. So in Python, these are called libraries and we can import libraries into our code as we need additional functionality. So the best place to start looking at libraries would be docs.python.org slash three slash library. And then this will, if you just look around a little bit, it'll show you different libraries that you can import and then what those libraries can do for you. So then you can include additional functionality in your code without you having to write everything from scratch. Now, these are all documents or libraries that the Python organization kind of maintains or recommends, but there's a lot of other libraries that are available on, for example, GitHub that you can download from normal users, or you can even write your own libraries and include them in your packages. So imagine that you're trying to write a new program, you could create libraries for your program, and then include those libraries in any additional programs you write in the future, which is really common to do. So, yeah, libraries are just additional code that you can include into your script. So you can use functions from that, that included code. So today, just to kind of demonstrate, I'm going to use one of my favorite libraries, which is the random library. So to import it, all we do is use the import keyword. And you can see that it's kind of like, I don't know, a dark brownish, it's a brown, detected as a brownish color. This is a keyword for Python. So import. And the library that I want to import is random. And this is, if you have Python installed, you probably also have random installed. You don't use random in every single piece of code you'll ever write, but it is quite common to see it here, and I like it. So I'm just going to use it. So that's it. Now I can use all of the functions that are included in the random library. As long as I have the random library installed on my computer, and I do, then I can use any of the functions that that library would give me. So one way to use this, I'm going to use the print command just so you can see the output. Now I can call the code. So anything I want to call, let's say random dot, let's do a choice, random choice. And then, let me type this all out. And then explain it. Okay. Need another one. Right. So you already know what print means. So next is random. And this is basically saying import anything imported from random, use functions from that. This dot means a function or a method from that library. And then the function's name is choice. And I know that this is a function or a method because I have the brackets here like we saw in the last video with a parameter or an argument inside the function that I'm calling. So random has a function called choice. And then we can give it some sort of value. And we can send that to the function. So here, what am I actually sending to it? Well, this is a list or an array, if you remember from a couple videos back, and we just have a array of three different values, red, green, and blue. Okay. So can you guess what this does? We're importing code from random. And then we're using a function called random dot choice. And that probably gives everything away, right? And then we feed it three different values. So let's go ahead and run this. And then we get blue. Well, what happens if we run the code again? Okay, every time we run the code, we're going to get a different value. And sometimes it will be the same value multiple times because it's a completely random choice. It's one out of three, every single time. Okay. Another function that we commonly use with random would be something like rand int. And then zero, 10. Now notice that these functions are written with names that kind of tell you or give you a general idea of what they should do. So in this case, random dot rand int, what do you think that that does? It also a function or method. And we're giving it a value zero and 10. So most likely, it gives you back a random integer between zero and 10. Okay. And that's what it does. So let's take a look at it. So every time we run the code, we get four. Next time four. Okay. So every time we run the code, we'll get a different integer between zero and 10 because of this function rand int and the values that we're giving it. Okay. So I don't want to make this whole thing about random, the random library. So those are two functions that we commonly use choice and rand int to randomize what's happening whenever your script runs, especially if you're playing or writing a video game or something like that, you'll probably use that. But we're talking about imports. So another way to import, let's say I don't want to type out random a lot. Notice I have to type out the name of the library here, I can import random and then say as r. And I'm just going to give it a capital R here. And then instead of typing random every single time, I can just do r and then dot the function. So here we've assigned the name r to the random library. And if we run that code again, we still get exactly the same functionality. Just I have to type less because I've imported it with a different name. Okay. So the functionality doesn't change just less typing basically. Okay. And then one more thing that we can do, let's say that I in random, random has a lot of different functionality that's available. But maybe I only care about the function rand int. I'm not going to use any other function from this library. So instead of importing the entire library, I can just import only the one, the piece of functionality that I want. So I can import it by doing from random import rand int. Okay. So from random, import rand int. So here I'm saying which library I need to import from and then which functionality I actually want. And then I won't import anything else except this rand int function. So now I can completely drop the library name and just do rand int zero 10. And if we if we run this code again, then we still get the same functionality. Okay. And of course, at the end, I can put as r. But now we're kind of getting down where you might not remember what r actually means. And we get the same functionality. So if you know which functionality you actually want, you can import it with a specific name. Otherwise, you can just import it with its own function name. Or you can import the entire library and then use different functions or methods from that library. Okay. Now, importing any library is essentially the same. They will all have different functions or functionality in the libraries themselves. So you do need to look up what your library is actually going to do. But there's a lot of documentation online. If there's something that you want to do, you're probably going to import some type of library for that functionality. The way the easiest way to do it is just type import the library, right? Other than that, you can do from library import function. Okay. If you know exactly what functionality you want. So that's pretty much the basics for importing. This happens a lot. And like I said, our imports normally go at the beginning of the script. You can put them in anywhere, but you have to import them before you use them, obviously. Okay. So we'll work a lot more with imports in the videos to come. So that's it for today. Thank you very much.