Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Python Basics: Functions and Loops (Summary)

In this video course, you learned about two of the most essential concepts in programming: functions and loops. First, you learned how to define your own custom functions. You saw that functions are made up of two parts:

  1. The function signature, which starts with the def keyword and includes the name of the function and the function’s parameters
  2. The function body, which contains the code that runs whenever the function is called

Functions help you avoid repeating similar code throughout your program by creating reusable components. This helps make your code easier to read and maintain.

Then you learned about Python’s two kinds of loops:

  1. while loops repeat some code while a given condition remains true.
  2. for loops repeat some code for each element in a set of objects.

For more information on the concepts covered in this course, check out the following tutorials:

Or you can explore the following video courses:

To continue your Python learning journey, check out the other Python Basics courses. You might also consider getting yourself a copy of Python Basics: A Practical Introduction to Python 3.


Sample Code (.zip)

552 bytes


Course Slides (.pdf)

9.0 MB

00:00 Congratulations, you made it to the last lesson of Python Basics: Functions and Loops. In this course, we talked about pancakes, donuts, and ice cream. And besides that, we also talked about how to execute functions, you learned how to create your own functions, and how to document them.

00:21 At the beginning of the course, you played around with the type() function and found out what built-in functions are. And later, you created your own function, shout_and_return().

00:34 This function replaced the print() function and had this difference that it actually returned something. Last but not least. You also created a docstring for shout_and_return(), and you verified that everything works fine by calling the help() function, passing in your function name.

00:57 This course covered the basics of creating your own functions, but if you want to look a bit deeper into the topic, you get a recap as well as a deep dive in our tutorial Defining Your Own Python functions. Also, we have a more in-depth guide about documentation.

01:15 It’s called Documenting Python Code: A Complete Guide. Besides the docstring that you already met in this course, you will dive even deeper into the topic and learn about different forms of documenting your Python code. The Python return Statement: Usage and Best Practices is a step-by-step tutorial.

01:36 You will learn how to use the return statement when writing functions, and additionally, you’ll cover some good programming practices related to the use of return. With this knowledge, you’ll be able to write readable, robust, and maintainable functions in Python.

01:52 These three resources are a great way of diving a bit deeper into the stuff that you learned in this course,

02:02 but if you expand your knowledge even more, we have some additional resources. So there were a few details that we didn’t tackle in this course. One of them was Python scope. In Python Scope & the LEGB Rule: Resolving Names in Your Code, you will learn what scopes are, how they work, and how to use them effectively to avoid name collision in your code. Additionally, you’ll learn how to take advantage of a Python scope to write more maintainable and less buggy code.

02:35 We also didn’t talk much about arguments of functions. Using Python Optional Arguments When Defining Functions is a good choice to get more into this topic.

02:47 In this tutorial, you’ll learn about Python optional arguments and how to define a function with default values. You’ll also learn how to create functions that accept any number of arguments using args and kwargs.

03:01 And then there are inner functions. In Python Inner Functions: What Are They Good For?, you will learn what inner functions are, how to define them, and what their main use cases are.

03:15 Almost all of the resources on the last two slides have articles and also video courses, so feel free to choose the format that you want to learn with. And now let’s have a look at the second big part of this course.

03:31 The second part was all about loops. You learned how to write while loops and for loops, what they are. You also learned how to terminate infinite loops.

03:42 That’s a real important thing. And you compared while and for loops so you can decide on your own which kind of loop you want to choose for your programming endeavors.

03:56 In this slide, again you see the examples that we tackled during this course in the loops part. On the left side, you see the while loop examples and how to build them. On the right side, you see the for loops. And here again, although the examples are not entirely the same, on the right side, you see that for loops tend to be much cleaner than while loops.

04:21 But still, there are situations where while loops make sense, so that’s the example on the lower left. When you have a user input, then the while loop is your loop of choice.

04:36 Just like with the functions, we also have resources for while loops and for loops. So if you want to read more about them, you can check out the Python “while” Loops article, or if you want to learn more about the for loops, you can check out the Python “for” Loops article. For both of the articles, we also have courses, so choose any format that you like.

05:02 And that’s a wrap. Thank you so much for joining me in this course, and have fun using functions and loops in Python. See you next time.

Become a Member to join the conversation.