Reputation: 9
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
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
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