filmov
tv
Python - Functions with Optional Arguments

Показать описание
#Python #Shorts
It is somewhat common to have functions that have arguments that are optional. To create such a function, your arguments need default values. To achieve that, just set the default value right in the function definition. Be careful though, optional arguments MUST appear after all other arguments. And lastly, don't ever use mutable types, such as lists, as default arguments. Use None instead.
-------------------------------------------------------------------------------------
Links:
It is somewhat common to have functions that have arguments that are optional. To create such a function, your arguments need default values. To achieve that, just set the default value right in the function definition. Be careful though, optional arguments MUST appear after all other arguments. And lastly, don't ever use mutable types, such as lists, as default arguments. Use None instead.
-------------------------------------------------------------------------------------
Links: