本文主要是介绍《python语言程序设计》2018版第8章第2题检测子串,你可以用str类中的find方法检测一个字符串,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
我先用in来做一次
def find_text(text_input1, text_input2):a = str(text_input1)b = str(text_input2)if b in a:print(f"The {b} is in {a} ")else:print(f"The {b} is not in {a} ")text_n1 = "Welcome to shenyang"
text_n2 = "to"find_text(text_n1, text_n2)
使用find
def find_text(text_input1, text_input2):a = str(text_input1)b = str(text_input2)if a.find(b) != -1:print(f"The {b} is in {a} ")else:print(f"The {b} is not in {a} ")text_n1 = "Welcome to shenyang"
text_n2 = "to"find_text(text_n1, text_n2)
这篇关于《python语言程序设计》2018版第8章第2题检测子串,你可以用str类中的find方法检测一个字符串的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!