在下面的代碼中,我想計算序列中G和C字符的百分比。在Python 3中,我正確地得到了0.5
,但在Python 2上,我得到0
。爲什麼結果不同?Python 3中的分區給出的結果與Python 2中的不同
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')
可能重複](http://stackoverflow.com/questions/2958684/python-division) – Bakuriu