我需要检查子字符串是否是特定字符串的一部分。子字符串是“AAA”,如果在给定字符串中找到它,它必须返回True。如果它不在字符串中,则必须返回False
def isResistent(virus):
gen = "AAA"
if gen in virus:
print("True")
else:
print("False")
isResistent('GCAAGCTGGTCGTGAAAGCT')
它返回True或False,但除了True或False之外,它首先给出索引号或其他内容。当我多次运行该程序时,它返回:
输出:
^{pr2}$有可能只打印真假吗?在
如果使用
return
,则函数工作正常:我还将包含
^{pr2}$gen
作为函数参数,以便您将来可以测试"AAA"
之外的其他子字符串:你的函数应该是
return 'AAA' in virus
。在相关问题 更多 >
编程相关推荐