For more information on concepts covered in this lesson, you can check out Python Scope & the LEGB Rule: Resolving Names in Your Code.
Creating Functions With No Input Parameters
00:00 Defining Functions With No Input Parameters. In this course, you’ll use the example of a basic program that creates and maintains a shopping list and prints it out when you’re ready to go to the supermarket.
You don’t need any input parameters in this example, since the dictionary,
shopping_list, is a global variable. This means it can be accessed from everywhere in the program, including from within the function definition. This is called the global scope.
01:34 You can read more about scope in this Real Python tutorial. Using global variables in this way is not a good practice. It can lead to several functions making changes to the same data structure, which can lead to bugs that are hard to find.
01:51 You’ll see how to improve on this later on in this course, when you pass the dictionary to the function as an argument. In the next section, you’ll define a function that requires an input argument.
Become a Member to join the conversation.