【发布时间】:2019-10-11 13:51:44
【问题描述】:
我应该编写一个 python 3 函数,它接受三个参数 - 两个 DNA 片段字符串,然后是一个 3 碱基基序,如果两个 DNA 片段都包含该基序,则返回 True,否则返回 False。 我已经编写了函数,但是它返回 True 或 False AND None... 为什么? 谁能告诉我这里有什么问题?
def common_motif(dna_seq1, dna_seq2, x):
"""This function returns True if both DNA segments contain the motif, and False otherwise"""
count_1 = dna_seq1.count(x)
count_2 = dna_seq2.count(x)
if count_1 > 0:
if count_2 > 0:
print(True)
else:
print(False)
print(common_motif("GATGCGCACGCG", "ATGGATTACCAT", "GAT"))
True
None
【问题讨论】:
-
您正在打印
common_motif的结果(common_motif返回的对象)。由于该函数没有显式返回任何内容,因此默认返回None。因此,您正在打印None。您还可以打印True或False作为调用函数的副作用。