That’s twice today you’ve helped mtf, thanks again. I think that I’m used to mixing numerics, in the same statement, with strings like you can (I believe) in JavaScript.
Change the print statement in the function to print “Creating a spreadsheet called title with row_count rows”, where title and row_count are replaced with their respective values.
Remember, to concatenate a number to a string object, you’ll first have to cast row_count to a string using str() . Otherwise, you’ll get a TypeError .
There’s a big problem with that, it tells me “Remember” but it was never brought upon any of the previous topics on how to interpolate ints in a string…
Where did all of this come from? Did I miss something? All the sudden there’s a bunch of +'s, and a “str” I’ve never seen before.
This part messed me up
("creating a spreadsheet called “+title+” with "str(row_count)+“rows.”)
Where did that come from??? I had to click view solution cause I just couldn’t get it and then it hits me with this stuff I’ve never seen and could never have guessed.
It would have come up in the unit on strings and string formatting, and str() may be introduced in the built-in functions unit. Since concatenation is a rather simple concept there is probably not much time spent on the narrative and not many examples.
The thing to keep in mind is we are building a string from mixed data. All that data needs to be cast to the str type in order for the concatenation to be successful (with raising an exception). That is why we recast numbers (int, float) to string objects in this process. The object itself is not altered, only its representation within the string output.
You may feel blindsided at times in these courses but the onus is on us to keep a cool head, go back through the lessons (and our notes), do a quick search of the documentation to look up functions that are new and unfamiliar to us so we learn what they offer.
Yes, so long as we don’t go overboard. The simpler the function and the fewer the parameters the easier to debug and maintain. Better to have three simple functions than one huge complicated one. Defaults should be able to apply in all situations where positional arguments are not present.
Thanks! But why not have default arguments for all the parameters? It seems like a good safeguard, especially considering missing parameters cause so much problems in languages like C.