FAQ: Code Challenge: String Methods - Check Name

This community-built FAQ covers the “Check Name” exercise from the lesson “Code Challenge: String Methods”.

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

Learn Python 3

FAQs on the exercise Check Name

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

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!

2 posts were split to a new topic: Does .lowercase work on uppercase?

2 posts were split to a new topic: Why doesn’t my code work?

A post was split to a new topic: My solution

def check_for_name(sentence, name):
  for i in sentence.split():
    if i.lower() == name.lower():
      return True
  for y in sentence.split():
    if sentence.find(name) == -1:
      return False

This was my solution. Not at all streamlined like the solution provided by CC.

I think its a good challenge to see if you can simplify your solution

Yea, you’re right. The solution given by CC was much better than mine

How can

[spoiler]This text will be blurred[/spoiler]
return name.lower() in sentence.lower() 

return True or False?
I thought it will return name.lower()

[spoiler]This text will be blurred[/spoiler]
def check_for_name(sentence, name):
  return name.lower() in sentence.lower()

The in keyword is used for a membership test and will result in a boolean.

1 Like

Thank you. Now I understand. :smiley:

1 Like

Screen Shot 2020-03-27 at 4.04.16 PM
instead of finding the Trues one by one, I tried to find one False and use an else statement after that. maybe not the best wa.