FAQ: Introduction to Functions - Keyword Arguments

#21

Hi all,
Somehow my code does not work, I tried to get it working like this:

Define create_spreadsheet():

def create_spreadsheet(title+row_count):
print("Creating a spreadsheet called "+title)

Call create_spreadsheet() below with the required arguments:

create_spreadsheet(“Downloads”)

row_count = 1000

that`s my Code

and here is the error message that i´m recieving

File “script.py”, line 2
def create_spreadsheet(title+row_count):
^
SyntaxError: invalid syntax

i could click on “Solution” but the i would see all of the code in the exercise, wich contradicts the purpose of learning by doing.

I hope somebody can help me.
Thank`s in advance.

#22

We cannot write operator expressions in the parameter. It should be a comma separated list. Any keyword arguments should appear last in the list.

def create_spreadsheet(title, row_count=1000):
1 Like
#23

I don’t quite understand why do we need to have the string command for the row_count below?

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

#24

Because row_count is an integer and we cannot concatenate an integer (or a float) to a string. Using the str() constructor casts the number to a string type so it can be concatenated.