在进行简单搜索时,不论大小写可以通过以下方法实现:
keyword = "apple"
target_string = "I like Apples"
if keyword.lower() in target_string.lower():
print("Match found")
else:
print("No match found")
import re
keyword = "apple"
target_string = "I like Apples"
pattern = re.compile(keyword, re.IGNORECASE)
if re.search(pattern, target_string):
print("Match found")
else:
print("No match found")
以上两种方法都可以实现在进行简单搜索时不论大小写。