Codecademy Forums

Why do we need brackets and a comma in this expression?

In this exercise, we use this line of code to remove the % signs:

students.score = students['score'].replace('[\%,]', '', regex=True)

Why do we need the brackets and the comma inside them?

Do you think it should behave the same way without them? Do you know what the brackets do? If not, then finding that out may let you answer yourself.

Or, if you can remove them and still get the same outcome, then you’ve proven that they’re not needed.

That pattern doesn’t only match on % so… maybe there’s a different intention behind it than

3 Likes