dimanche 8 août 2021

python for loops: What does this does?

I am new to python, i was working with python random module and for loops.

accidentally I typed this

from random import choice

secret_num = []
for i in range(4):
    num = choice(range(10))
    secret_num.append(secret_num)

print(secret_num)

instead of appending num to secret_num list i appended secret_num

but now i am curious what this program does.

I got this output:

[[...], [...], [...], [...]]



Aucun commentaire:

Enregistrer un commentaire