[FIXED] Putting quotation marks around variable names when concatenating strings

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 first_name and last_name . The function should return the last_name , followed by a comma, a space, first_name another space, and finally last_name .

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 last_name.

As you can see, they put quotation marks around the variable names first_name and 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:

print(introduction("James", "Bond"))

The output looked like this:

Bond, James Bond

So, what’s the deal with the quotation marks around the variable names?

1 Like

You can’t do that.

You can concatenate two strings. What you probably mean is that your variable refers to a string.

Is that series of characters interesting to you? Usually what you’d want from a variable is the value it refers to, not the name of the variable.

What do quotes do? Would they do anything different because there happens to exist a variable matching what you’ve put between quotes?

Thanks for responding to my question, but I actually do not know if quotes would do anything different when put around a variable name - that is why I asked the question. I’m still a little new to programming. Would putting quotes around a variable name such as first_name simply print the output first_name instead of printing the value of the variable first_name? If that is the case, then I am confused as to why the hint would put quotes around the variable first_name because the goal was to print the value of the variable first_name which was James.

You’d use quotes when you want to represent text.
A variable is not text.

Variables support two things.
Assign
Read

Use them to hold on to values for later use.

If you for example write this:

"abcde"

Then you will have this in memory:

[97, 98, 99, 100, 101]

Though, memory stores ones and zeros, not … that, so:

0110000101100010011000110110010001100101

variables? got nothing to do with it.

Hello, @okaraman7.

Your code is correct, and the hint is wrong. This is a bug in the lesson. Just for reference, I’m pasting a screen shot:
image

The code in the hint should be:
last_name + ", " + first_name

Yes. As @ionatan has said, "first_name" is simply a string whereas first_name could be a variable assuming we are using it as such i.e. first_name = "James". I’ll report this as a bug, so the Codecademy team can correct the hint. Thanks, for pointing out the mistake! :slightly_smiling_face:

1 Like

They fixed this one very quickly! Thanks again, @okaraman7, for bringing this to our attention!

1 Like