0

I want to make a global list and I saved a value in my global list (def rand()).

Whatever I save, my saved value doesnt include at another function except rand().

What am I missing?

sayi = []

def rand():

    global sayi
    initial = 1000
    for i in range(1000,10000):
        initial +=1
        sayi.append(initial)
    print sayi[43]


def main():

    rand()
    print len(sayi) # Shows 0 but I have added value at rand funct. with append funct.
main()
4

1 回答 1

0

我假设您是 python 新手。压痕问题。不想刻薄,但我注意到这会让很多人感到沮丧。这是您修改后的代码。

sayi = []

def rand():

    global sayi
    initial = 1000
    for i in range(1000,10000):
        initial +=1
        sayi.append(initial)
    print sayi[43]


def main():

    rand()
    print len(sayi) # Shows 0 but I have added value at rand funct. with append funct.

main()

你一切正常,你的缩进只是一点点。

于 2012-10-26T22:45:38.977 回答