Locked learning resources

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

Unlock This Lesson

Locked learning resources

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

Unlock This Lesson

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.

Download

Sample Code (.zip)

552 bytes
Download

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.

Avatar image for alex opoku

alex opoku on Sept. 9, 2023

This lesson is great I enjoyed it.

I am having problems with the certificates I receive for the courses I have successfully completed. I am unable to read all the text on the certificates.

I want to find out if there would be another certificate upon completing all the modules in a given course.

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on Sept. 11, 2023

@alex opoku A certificate gets issued after completeing all lessons in a course. What do you mean you can’t read all the text on your certificates?

Avatar image for alex opoku

alex opoku on Sept. 12, 2023

Thank you for your comment. Indeed, I have notifications of for certificates for the courses I have completed. However, whenever I open them some of the text on the certificate overlaps with the image part of the certificate, causing some of the text not to appear at all.

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on Sept. 12, 2023

@alex opoku Oh, really? Maybe that’s a browser issue. Have you tried opening the certificate page in another web browser? Could you please share the link to your certificate and possibly a screenshot so that we can investigate? Thanks!

Avatar image for alex opoku

alex opoku on Sept. 18, 2023

This a link for one of the certs realpython.com/certificates/54ca2298-51da-4c55-9e2e-10d5d2e60d36/

Unfortunately, I am unable to attach screenshots and pdf copy of the cert.

I am using Google Chrome browser. Which other one would you recommend?

Thank you

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on Sept. 19, 2023

@alex opoku The certificate looks fine to me, as it renders correctly in all web browsers installed on my computer. Can you go over to Slack and share your screenshot there? If you haven’t joined the Real Python Slack Community yet, then now you have a great opportunity 😉

Become a Member to join the conversation.