Reputation: 67
I know similar questions have been asked but before you down vote, hear me out.
If I want to check lets say if the string "Daniel" is located anywhere in "danielrydg123" ignoring capitals (should return true if the second string was "Danielrydg123" or "danielrydg123") how would I do this?
Upvotes: 0
Views: 50
Reputation: 5774
if "Daniel".lower() in "Danielrydg123".lower():
print("found it")
Output:
found it
I suggest you review string methods
Additionally you can use .find()
as @Bucket has pointed out, which would translate into an if
statement like:
if "Danielrydg123".lower().find("Daniel".lower()) >= 0:
print("found it")
Output:
found it
Upvotes: 3
Reputation: 7521
User find()
str1 = "123Danielrydg123"
str2 = "noPe"
sub = "daniel"
str1.lower().find(sub) # returns 3
str2.lower().find(sub) # returns -1
Upvotes: 2