What is the point of using a keyword?

Hello all, first timer here.

I was wondering what the point of keywording something in the parameter is ? In the example of the exercise that have been mentioned in this thread:

def greet_customer(special_item, grocery_store=“Engrossing Grocer’s”):
print("Welcome to "+ grocery_store + “.”)
print("Our special is " + special_item + “.”)
print(“Have fun shopping!”)

Engrossing Grocer’s has now been keyworded into the parameter’s positional arguements.

It seems to me that this is extra work and redundant coding, since keywording something to a parameter is pretty much the same as me doing this :

def greet_customer(special_item):
print(“Welcome to Engrossing Grocer’s.”)
print("Our special is " + special_item + “.”)
print(“Have fun shopping!”)

now isn’t that pretty much the same as me keywording it into the parameter ? but with less code ?
or does keywording something as in the example have broader uses ?

also, on a side note. How do I store a functions output as a variable ?


def somernumbers(number, x, y)
print(number + x*y)

somenumbers(5, 3, 2)

now that prints the number to the console, but
how do I go about storing that number/function as a variable ? I’ve tried all sorts of things, but with no luck.

Thank you all so much in advance.

It is not the same. That example has hard coded a literal into the function body, and does not allow for a second positional argument. By keywording a default value, we may still replace that with a literal argument in subsequent calls.

>>> def add_to_list(temp_list=[], item='temp_item'):
    return temp_list

>>> my_list = add_to_list()
>>> my_list
>>> my_list = add_to_list(['existing item'])
>>> my_list
['existing item', 'temp_item']
>>> my_list = add_to_list(['existing item'], 'new item')
>>> my_list
['existing item', 'new item']