Features of working with default parameter values in Python functions
Many beginning (and not just!) programmers in Python eventually encounter unexpected behavior of functions where the default parameters contain lists, dictionaries or other mutable data types. Why does the function suddenly "remember" old values between calls? Is it a bug? Magic? Or... a Python feature?
In this video I go into detail about how Python handles default values when declaring a function. You'll learn what actually happens at the moment of function creation, and why specifying a mutable object as a default value can lead to unexpected (and sometimes very unpleasant) consequences.
Timestamps:
00:00 Introduction
00:29 Let's analyze the code example
06:44 Working with default parameter values
11:02 Conclusions
#python #functions #defaultvalues #mutabletypes #bugs #pythontips #programming