r/learnpython • • 2d ago

Function without argument

Ive got a function that takes a dictionary as an argument.
Now Id like to program it so when the function is called without any argument, instead of an error message it prints something custom (a dictionary for example).

Any help is appreciated :D

1 Upvotes

16 comments sorted by

View all comments

1

u/Classic-Rate-5104 2d ago

Many answers suggest function(argument=None) and then testing for "argument is None". Why not simply function(argument={}) or whatever default you want?

1

u/jonrsharpe 1d ago

A mutable default value is a famously bad idea: https://stackoverflow.com/q/1132941/3001761