FAQ: Code Challenge: String Methods - Every Other Letter

#1

This community-built FAQ covers the “Every Other Letter” exercise from the lesson “Code Challenge: String Methods”.

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

FAQs on the exercise Every Other Letter

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!

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

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

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!

#4

Isn’t it easier to write:

5 Likes
#5

Would anyone be able to tell me why the given solution to this problem works? In an earlier lesson we learned that strings are immutable. It seems like the process of iterating through the letters in the given word and then adding every other one to the string every_other would necessarily require us to change the string every_other.

Is it that strings can be added to, but the individual characters in strings can’t be removed or swapped without creating a new string?

#6

It would seem that way, although we are not changing it, but replacing it with a new composed string value

Only when we do it on the right side of an assignment (or in an argument) using concatenation (or other method) to build the desired string expression. Each time we assign it to the left side. If that is the same variable, then we have replaced its value with the new one.

if a and b are string values,

a = a + b

replaces a with the joint string value. The right hand side is not mutating a string, but creating a single string value.

a += b

says the same thing using the compact assignment operator.