1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Why is my list not updating when I use append inside a loop in Python? [closed]

Discussão em 'Python' iniciado por Stack, Novembro 30, 2025.

  1. Stack

    Stack Membro Participativo

    I’m trying to add numbers to a list using a loop:

    nums = []
    for i in range(5):
    nums.append(i * 2)
    print(nums)


    But the list prints [] instead of values.
    Am I missing something basic?
    How can I correctly append elements to a list?

    Continue reading...

Compartilhe esta Página