Keyword Arguments - What gets printed upon calling functions with keyword arguments?

Hello people,

In the context of this exercise,, I don’t quite understand why adding the first keyword argument does not change what gets printed to the terminal:

draw_shape(shape_name="box", character="m", line_breaks=False)

If I’d just try:

draw_shape(character="m", line_breaks=False)

I get the same result.

Also, when we have keyword arguments provided as parameters in a function and we then want to call it with different values for these parameters, do we still have to type in the name of the parameter and set it equal to the new value of the argument that we are passing?

Many thanks in advance.

There’s a couple of things on the go here. The draw_shape function has three arguments with default values (default arguments). You might need to separate the terminology here to understand the differences. The tutorial in the docs has a few examples of this that may help-

If you were to call this function without any other arguments, draw_shape(), it runs as if you passed those values as arguments to the function, shape_name="box" etc…

In your example your arguments are no different to the defaults so the function behaves in the same way. Try altering these arguments, e.g. character="O" if you want to see the differences.

Keyword arguments are those passed to a function with a given parameter name (name=x). So the name keyword arguments refers to those you include in the function call itself (not in the definition of the function, those would be the default arguments).

You could pass those values in as positional arguments… e.g. draw_shape("box", "o", True) but being positional the order must then match the order of the parameters themselves so no you don’t have to pass keyword arguments in.

This reply might be useful if the two terms are still not clear-

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.