在下面的代码中,我想计算一个序列中 G 和 C 字符的百分比。在 Python 3 中我正确地得到0.5
了,但在 Python 2 中我得到了0
. 为什么结果不一样?
def gc_content(base_seq):
"""Return the percentage of G and C characters in base_seq"""
seq = base_seq.upper()
return (seq.count('G') + seq.count('C')) / len(seq)
gc_content('attacgcg')