FAQ: String Methods - .find()

This community-built FAQ covers the “.find()” 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 .find()

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!

8 posts were split to a new topic: What causes .find() to return -1?

What’s the difference between string.find() and string.index() ?

Seems you are not the first person to ask this question:

https://stackoverflow.com/questions/22190064/difference-between-find-and-index

2 Likes

.find() returns the first index value where that string is located.

why does this code return 20?

god_wills_it_line_one = "The very earth will disown you"

disown_placement = god_wills_it_line_one.find('disown')
print(disown_placement)

it literally explained in the lesson:

You can also search for larger strings, and .find() will return the index value of the first character of that string.

1 Like

I don’t think you should be a Volunteer Moderator with answers like that. He has a legitimate question if you follow the question that is asked. Codecedamey has this tendency to teach something one way and then ask a question in a completely wrong wording type that confuses a lot of newcomers.
’ At what index place does the word “disown” appear? Save that index place to the variable disown_placement
It’s asking where does the WORD APPEARS, not at which index the word BEGINS. The two are very differently worded. It confused me at first too and I fully understand the concept from learning it in other courses. I thought it was asking me to write an entire loop to account for every index of the character in a string.

1 Like

I would consider this good practice then. If you find this confusing, dealing with clients who don’t even know what they want is a whole other level

being able to not get confused by different wording and being able to understand the requirements is a huge part of programming.

While I agree with you completely about that. I don’t think you should be having different wording on a platform that tries to teach you how to code, and is still very much in the beginning stage of that. That’s like telling someone figuring out theoretical physics is part of their job, while they are literally taking physics 101 in high school. Like what kind of answer is that?

How do I make my .find() search case insensitive?

By applying the .lower() or .upper() method to the string, then search for that case.

>>> a = "A quick brown FOX jumps over the lazy dog"
>>> a.lower().find('fox')
14
>>> 
1 Like

Thank you, mtf!
Just convert the whole string to one case. Simple enough

1 Like

god_wills_it_line_one = “The very earth will disown you”

disown_placement = god_wills_it_line_one.find(“disown”)

print(disown_placement)

Hi, This piece of code prints 20 as the index value. What if there are multiple words in a sentence which has the same starting letter as “d”. This find method does it only look for the starting letter “D” or for the entire substring that’s given as argument. Can someone please explain?

This question is answered above. :arrow_up:

You can also check out the Python docs: