黄河大合唱123 发表于 2014-07-09 18:49

[问题]for循环后跟着if判断,但是if部分却没有执行?

#! /usr/bin/python

dna={
        'A' : '0',
        'C' : '1',
        'G' : '2',
        'T' : '3'       
}

print 'all dna-int pairs are: '
print 'the length of the dic=%d' %len(dna)
for dna, inte in dna.items():
        print '%s %s' % (dna, inte)

if 'A' in dna:
        print '\n"A" refer to the integer %s in the dict' % dna['A']
多谢各位大牛!

q1208c 发表于 2014-07-09 19:16

回复 1# 黄河大合唱123

变量名 冲突了. dna 这个变量在 for 里被重新定义了.
   

黄河大合唱123 发表于 2014-07-09 19:34

OK。多谢啦!回复 2# q1208c


   
页: [1]
查看完整版本: [问题]for循环后跟着if判断,但是if部分却没有执行?