FAQ: String Methods - Replace

This community-built FAQ covers the “Replace” exercise from the lesson “String Methods”.

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

Computer Science

FAQs on the exercise Replace

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!

Why that ‘’ is used in line one?

A post was split to a new topic: What does /g do?

What if we use .replace() without any argument? What will happen? Like, we can use .split() without any arguments and it works, what is the default argument for .replace()?

There’s no need to guess, best option is just to check the call signature of this method in the docs: https://docs.python.org/3/library/stdtypes.html#str.replace.

You could also just test the result (if you wanted to know why it fails though, see above :slightly_smiling_face:) -

"a string".replace("a")

If I’m being honest I find the python official documentation a little hard to read and understand. Any tips?

You might need a little info about the notation to get started: https://docs.python.org/3/reference/introduction.html#notation (I think this one carries through to the regular documentation too). Otherwise it’s something you’ll get better used to the more you actually use it.

It’s often helpful to run a quick interactive session to test things too, help("".replace) for example should give a quick overview of the method and you can play around with it from there.

I’ve downloaded anaconda but am struggling to use it a little bit - because otherwise I would just ‘play around with it’ as you say. I’ve done a few projects in Jupyter Notebook but that’s different. Spyder seems a bit clustered. What IDE would you recommend from Anaconda?