FAQ: Introduction to Variables - String Variables

This community-built FAQ covers the “String Variables” exercise from the lesson “Introduction to Variables”.

Paths and Courses
This exercise can be found in the following Codecademy content:

FAQs on the exercise String Variables

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hello. I have noticed some errors and inconsistencies. I am a beginner who is currently doing the Learn with Blockly Lessons

On page 3, there is an error where the example first uses 10000 but then says “1000.” Here it is and here is the link as well. https://www.codecademy.com/courses/learn-to-code-with-blockly/lessons/introduction-to-variables-learn-how-to-code/exercises/expressions-and-operators

Assigning Variables Using Expressions

Now we can assign a new ‘bonus points’ variable that rewards the player for completing the round quicker:

bonus_points = 10000 / time_taken_seconds# Set bonus points to 1000 divided by the number of seconds it took to win the level

The next mistake is on page 4. There is a sentence fragment that makes it hard to comprehend the meaning of the lesson. Here is the link
 https://www.codecademy.com/courses/learn-to-code-with-blockly/lessons/introduction-to-variables-learn-how-to-code/exercises/string-variables

"Let’s say we want two variables to hold parts of an a"

line1 = "123 Main Street"
city = "New York City"

I would like to continue with learning, but I want to make sure that I understand everything that is being said.

1 Like

in this line of code, "print(line1 + “, " + city)”
Could someone describe why you would use two “+” ?

You are referring to the code from the lesson,

line1 = "123 Main Street"
city = "New York City"

print(line1 + ", " + city)
# Outputs "123 Main Street, New York City" 

A string has been assigned to the line1 variable.
Similarly, another string has been assigned to the city variable.
", " is also a string (consisting of a comma character followed by a space character).

Since we want to concatenate/join three separate strings into a single string, so we need two + operators.

If we wanted to concatenate two strings into a single string, one + operator would be sufficient.

If we wanted to concatenate eight strings into a single string, we would need seven + operators.

As an aside, many languages have features such as string interpolation or template literals which allow for much easier creation of strings (as opposed to string concatenation involving many operators).