函数全局/局部变量更新问题

时间:2020-03-18 14:03:30

标签: python python-3.x function global-variables

有人可以指出为什么不输出此功能吗?请解释并举例。我只是无法弄清楚这个问题。

def double(lst):

    count=0
    result='Found'
    lsy=[count,result]

    for i in lst:
        word=i
        if 'mm' in word:
            result='Found'
            count=0
            break
        if 'nn' in word:
            result='None'
            count+=1

    return lsy

double(['Ammy','Timmy','Jimmy'])

3 个答案:

答案 0 :(得分:4)

       merge into sawyobi tgt
        using (select id
                 from dasaxeleba
                where barcode = NEW.barcode) src on (tgt.das_id = src.id)
 when matched then update set
              raodenoba = new.raodenoba,
              tvitgirebuleba = new.fasi,
              gasayidi1 = new.gasayidi1,
              gasayidi2 = new.gasayidi2
     when not matched then insert
              (das_id,
               raodenoba,
               tvitgirebuleba,
               gasayidi1,
               gasayidi2)
       values (src.id,
               new.raodenoba,
               new.fasi,
               ew.gasayidi1,
               new.gasayidi2)

答案 1 :(得分:0)

在函数调用上使用print()。否则,stdout不会得到任何信息,因此为什么您什么也看不到。

答案 2 :(得分:0)

如果您的意思是该函数产生错误的结果,则问题出在lsy上,因为在处理for循环中的result之后,您没有使用result更新它

如果您确实不是要显示输出,则只需打印结果:

print(double(['Ammy', 'Timmy', 'Jimmy']))