Learning about functions and arguments, My confusion is that I understand when you use a keyword argument, you’re giving a parameter a specific value, for example…

# Define create_spreadsheet():
def create_spreadsheet(title, row_count=1000):
  print("Creating a spreadsheet called "+title + " with " +str(row_count) +" rows")

# Call create_spreadsheet() below with the required arguments:

So in the function, as instructed, I’ve added the parameter “row_count” and gave it a default value of 1000, as you see when the function is called the value given for “row_count” is 10, and it works, showing the print line with the value of 10.

My question, How does that work, giving a different value when you call the function when in the function itself you’ve already given a specified and default value of 1000, how then does it work or what’s the point of giving a specific value if you can just change it to whatever you want when you call that function?

If the specified value for that parameter is 1,000, then shouldn’t it be a 1,000 every time it runs the function? Why am I able to make a specific default value for a parameter and then change it when I call that function?

Let us say that you are keeping records for your daily run. Most days, you run at the track in Echo Park, but occasionally you choose a different venue, so you have a function, daily_run():

def daily_run(date, begin_time, end_time, venue = "Echo Park"):

Now when you make your entries, you can just do them like this

daily_run("5/2", "13:21", "14:32")
daily_run("5/3", "13:35", "14:51")
daily_run("5/4", "14:15", "15:55", venue = "Long Lake")
daily_run("5/5", "12:01", "13:15")

In other words, if you expect the value to be unchanged most of the time, you can use a keyword argument, and then not even include it in the function call. The default will be used.



Thank you for taking time to explain this, now it makes more sense and I understand it.