FAQ: String Methods - Formatting Methods

This community-built FAQ covers the “Formatting Methods” 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 Formatting Methods

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!

In this lesson, the formatting methods are called without any arguments in the brackets. Is this always the case, or can they also be called with arguments in the brackets?

1 Like

you mean .title() and .upper()? Depends on the method signature, some methods don’t have any parameters, while other methods might optional or mandatory parameters.

Yes, like .title(), .upper() and .lower(). So are these methods never called with any parameters?

Well, parameters are “declared” along with the method. When we call a method we provide arguments for the parameters

These methods do not have parameters, so they are always called without arguments.

Why would these methods need parameters? We already have access to the string through the string

1 Like

Okay, I was just curious because other string methods do have parameters. Thanks for the clarification, I think I understand now.

So then the question you should be asking yourself is: Why does these methods do have parameters? Why is that needed?

for example, .split() might need an argument, depending on what character we want to use to split

.upper() converts to uppercase. So no need for arguments.

My assumption is that Python was never really intended as a word processor and that upper(), lower(), title() are primarily intended for data cleansing, but I’ll ask the question anyway. Is there a convenient way to ensure that the first letter of each sentence is upper case and everything else lower?

no built-in functions which can do this. You will either have to write your own or find a library/package which does this for you.

1 Like

Well, it would be useful if you wanted, for example, for any reason, to only convert the letters ‘A’ to uppercase. In that case, you could use ‘A’ as a parameter and the ‘uppercase’ method would only uppercase the 'A’s in a string.

That’s just my opinion…

I have a question around the use of .title() in my very limited experience with it, I have noticed if you use title with words that have been abbreviated such as “they’re” it will become “They’Re” . is there anyway around this? specifically one of the codewars challenges asks you to make the start of every word uppercase but using .title() affects the letters after the apostrophe.

@array8457324883 I had to do a bit of research on this myself but as others have mentioned, I don’t think Python was built with the word processing in mind as a function. Quick search shows that either you have to build your own function, or the best match would be to import the string library and use the capwords() function.