Python Challenges: Advanced Strings

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!


I ran into a curious issue while doing these challenges on codecademy. Each time i copy and paste the solution given it comes up with an error message. Usually the same error message. I am unsure what is wrong with the syntax that is creating th error. Any feedback would be greatly appreciated.

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

Hi,
The code you’re copy and pasting is using a different unicode for the quote marks. ‟ instead of " which is confusing the editor.
Replace them and it should be fine.

Hope that helps

Copy pasting code can be tricky as it may introduce some unintended effects.

Quote marks may be changed, hidden/invisible or invalid characters may be copied inadvertently (sometimes maliciously; google “pastejacking” for an example).

I copy pasted one of the solutions from the code snippets in Python Code Challenges: Strings

The problem is that there are invisible characters in the snippets, specifically the character U+00A0 (Non-breaking space) instead of spaces.

A good editor or IDE will show these hidden/invisible characters and allow you ways to remove/replace them. However, if you don’t have one at hand, you can copy paste the code, assign it to a variable as a multi-line string (using a pair of three quotes) and then print its repr:

scrn1

As you can see in the screenshot, there are a number of \xa0 characters which appear as normal spaces to the naked eye. The Unicode \xa0 represents non-breaking space.

We see uniques on the screen, but in reality the copied code is \xa0\xa0uniques which includes characters not allowed in Python variable names. Hence, the SyntaxError: invalid character in identifier message.

Thank you so much for answering and yes it makes sense.

I am very impressed by this answer , the technical detail included. It makes me realize how much work i have let to do. Thank you for your time.

1 Like