I'm wondering if there's a way to add an argument to the default arguments a function takes.
For instance:
SOME_CITIES = ["Gotham","Chicago"]
def do_something(name, cities=SOME_CITIES):
for city in cities:
print(name, city)
do_something("Clark")
>> Clark Gotham
>> Clark Chicago
# Can I do something like this (pseudocode, obviously):
do_something("Clark", *["New York", "LA"])
>> Clark Gotham
>> Clark Chicago
>> Clark New York
>> Clark LA
The idea is do_something("Clark", *"New York")
would run through the function, doing Gotham
, Chicago
, and then the city I added, New York
.
This is similar from my understanding of **kwargs
, but that would look like:
def do_something(name, **kwargs):
# Code here...
do_something("Clark", SOME_CITIES, "New York")
But that requires me to recall to send SOME_CITIES
through, when I'd like to include that by default. Does that make sense?
Edit: The SOME_CITIES
may not always be a list. It could be two functions, i.e. SOME_FUNCTIONS = func1, func2
. Also - as some answers seem to get at below, if this is a bad idea and kwargs
/args
is better, that's fine too just let me know and explain a little :)