Oct-09-2023, 01:50 PM
I'm working my way through _Teach Yourself Visually Python_ (2022). This example was presented:
I don't follow. Can someone give an example to illustrate this point and why using a mutable data type as default value might cause problems?
Thank you!
def parlay(odds1, odds2, odds3 = None, odds4 = None, odds5 = None): ...Following the example, a Tip is given about what data types to use for default values: "You can use most data types, including None, as in this example... However, in general, it is best to avoid mutable data types because although they work correctly the first time you call the function, subsequent calls to the function will return the last call assigned to the data type. For example, if you use an empty list as a default value, the first call returns an empty list, as expected, but the next call returns a list containing the values you assigned to the list."
I don't follow. Can someone give an example to illustrate this point and why using a mutable data type as default value might cause problems?
Thank you!