Jasraj Singh
Jasraj Singh

Reputation: 9

Finding a word in a string in python

i am just trying to find out a word noone in a string whether it is in lower case or upper case or mixed.

This is the code:

post= "hi noone bro"
a = "noone"
print(a in post)

If I replace noone with noOne it shows False. How can I fix it?

Upvotes: 0

Views: 65

Answers (2)

Kamal Pandey
Kamal Pandey

Reputation: 1598

You need to convert both to either lowercase or uppercase using .lower() or .upper() or can do something like this.

post= "hi noone bro"
a = "noOne"
print(a.casefold() in post.casefold())

Upvotes: 0

Guilherme Borges
Guilherme Borges

Reputation: 165

You can apply .lower() or .upper() to strings when finding matches, effectively eliminating casing.

So this would return true: "noone".lower() == "noOne".lower()

Upvotes: 2

Related Questions