When we concatenate strings and variables, do we ever need to put quotation marks around variable names? For example, I’m working on a code challenge in the Functions section of this course, and these were my instructions:
Write a function named
introduction()that has two parameters named
last_name. The function should return the
last_name, followed by a comma, a space,
first_nameanother space, and finally
This is the code I wrote:
def introduction(first_name, last_name): output = last_name + ", " + first_name + " " + last_name return output
However, the “hint” that was given to me along with the instructions said this:
Use the + operator to concatenate strings together. Don’t forget to add the comma or spaces!
"last_name" + ", " + "first_name"is a good starting point. Just add a final space and
As you can see, they put quotation marks around the variable names
last_name. Is that necessary? Even though I didn’t put quotation marks around my variable names, I was still able to successfully print this:
The output looked like this:
Bond, James Bond
So, what’s the deal with the quotation marks around the variable names?