For more information on concepts covered in this lesson, you can check out Python Booleans: Optimize Your Code With Truth Values.
Understanding Common Default Values
Common Default Argument Values. In the examples you’ve seen previously, you used the integer
1 as a default value in one case and the Boolean value
True in the other. These are common default values you’ll find in function definitions. However, the data type you should use for default values depends on the function you are defining and how you want the function to be used.
add_item() function you wrote earlier, setting the quantity for a new item to
1 is the most logical option. However, if you had a habit of buying two of everything you purchase when you go to the supermarket, then setting the default value to
2 may be more appropriate for you.
01:08 This assigns a value whose data type is a string, but doesn’t put in any additional characters. You’ve modified the function so that both parameters have a default value, and therefore the function can be called with no input parameters.
Become a Member to join the conversation.