Welcome to the final lesson of this short course where we'll talk about functions. Functions are like mini computer programs they can include inside of a larger computer program. When you want to do a specific task. Functions let you take action on data or action in the world. Let's dive in to see what this means. In the last lesson, we had a command like this from helper functions import. Let me just run that now and okay, don't worry too much for now about what exactly this is doing. And remember, please run every code cell in order. You've already encountered and used a few different Python functions in the lessons of this course. The first was the print function, which you can use to display text like this funny figure to the screen. And in the previous video you saw a more complex function print LLM response. So, this function takes this input, a string. In this case your prompt, "What is the capital of France?" and sends it off to a large language model over the internet and then displays the AI's response to the screen. You've actually seen one more function already, the type function, which can tell you the data type such as string, float, or int of a value or variable. So, you've seen print. Print LLM response, as well as type. And these are all functions that you've used in the course. In this lesson, I'd like to dive more deeply into exactly how functions work. There's a function in Python called the Len function, which stands for length. And if you were to type Len, then give it the string "Hello world." This will take and input the string "hello world" and compute its length, specifically the number of individual characters, including punctuation and spaces that are in the string. And then when I print out the result, this prints 12. Here's another example of a Python function which is round. So this takes a number, say 42.17, and then rounds it to the nearest integer. So we were to take this and print the results of rounding. For the 42.17 I get 42. One of the things that functions are often used for is to perform a computation on data, and then to return some value. For example, the Len function takes as input the data and it counts the number of characters and returns the answer. Or round 42.17, it computes what's 42.17 rounded, and it returns 42. Sometimes functions are used to take an action, for example, to display a piece of information. So, print "hello world" takes a string "hello world" and it displays it. Let's take a deeper look at what exactly happens when you call the Len function on "hello world". Len is the name of the function, and when you call a function, you use parentheses to give it data, and in this case the string "hello world" is the data you're giving to the Len function. The common lingo for the data you provide a function is called the argument. If you're curious about why it's called an argument. So go ahead and ask a chatbot. And when a function returns a number like 12, we say that the function returns this result. We also saw the print function which displays what you provide. Print is the name of the function. We have the parentheses as usual, and then within the parentheses are the arguments of the data that is the string "hello world" that is given to the print function. So far the examples we're using, we are getting a result from a function and then printing it out. But you don't have to just print out the result of a function right away. I can define a variable string length equals Len "hello world". And then we can print string length. And this will print out 12. So in the code that I ran just now, you saw this command string length. That was the name of a new variable we're creating. So, a new box to hold data with the assignment operator. And then Len "hello world" returns the number 12 and so this is saying take the variable string length and set it equal to 12. Or put the number 12 inside the box labeled string length. So after you put 12 inside this box, if you then subsequently print string length it will print out the number 12. Here's a more sophisticated example. I'm gonna set name equal to Tommy. Potatoes equals 4.75. And I'm going to write a prompt which is an f-string to be: "write a couplet about my friend of this name who has about, let's round potatoes to the nearest whole number. Potatoes." And then response equals get LLM response to the prompt. And then print the response. So, get LLM response here, is a new function that we haven't used before. But what this does is exactly the same as print LLM response, except that instead of printing out the response, it calls ChatGPT in this case, gets response and returns it as a value, which we then store in this variable response. What this would do is create a prompt, write a couplet about my friend Tommy, who has about five potatoes, and then ask the LLM to write a couplet. Tommy's got five potatoes, quite a sight, In his hands, his heart is light... Not too shabby. I hope this gives you a sense of how you can use variables to sequence more complex computations together. And in fact, for developers, writing software using generative AI, this type of programming pattern is something you actually see very often. Where you have some variables construct a prompt, call a large language model, get a response, and do something else on top of that response. And so that's it. Congratulations and great work on getting to the end of this short course. You've learned the fundamentals of Python, including data types and how to do math and variables, and how to use functions and how to interact with a large language model using Python code. After this video, please do try the extra practice exercises at the bottom of the Jupyter notebook, because it's really by practicing that you learn and get comfortable with Python. Remember also at any time you can consult the chatbot for help or advice if you get stuck. It's a really useful companion to work through problems with, and when you're done with that, I hope you join me in the next course. To learn even more powerful Python features. You learn how to make a computer do the same thing over and over and over. And you learn how to get the computer to take different actions depending on the data it sees. And as you keep learning, I think you'll enjoy being able to do more and more amazing things over time with Python and with AI. Congrats again on finishing this course and I look forward to seeing you in the next one.