Python for loop没有迭代,

时间:2018-11-30 22:38:30

标签: python for-loop

该迭代仅运行一次,下面是我尝试运行的代码,

def heat_coeff(gas,Nu,d):
    """Calculate heat transfer (at interior tube wall)"""
    mass = gas *100
    diff = mass * 2
    for i in d:
        U = 4.*diff*Nu / (i*i)
        return U

heat_coeff(10,4, [1,2,3])

1 个答案:

答案 0 :(得分:1)

删除DefineBitsLossLess2Tag imgTag = tag as DefineBitsLossLess2Tag; imgTag.DecompileToFile(string.Format("output/{0}/{1}.png", item.Name, imgTag.CharacterId)); 内部循环,并将其放在外部。否则,您可能会过早退出!

return

但是,还有另一个错误。您打算对循环内的for i in d: U = 4 * diff * Nu / (i*i) return U 做什么?您必须在每次迭代时更新,否则,您只会得到上一次迭代的值。

编辑:

现在,您已经在注释中解释了您的需求(首先应该是在问题中),这就是您打算做的事情:

U

例如:

def heat_coeff(gas, Nu, d):
    mass = gas * 100
    diff = mass * 2
    return [4.0 * diff * Nu / (i*i) for i in d]