[Python] "What's the difference between using append() vs extend() when working with Python...

Discussão em 'Python' iniciado por Stack, Abril 11, 2025.

  1. Stack

    Stack Membro Participativo

    I'm currently learning Python and working with lists. I came across two methods—append() and extend()—and I'm a bit confused about how they're different.

    For example:

    a = [1, 2, 3]
    b = [4, 5]

    a.append(b)
    a.extend(b)


    After running these, I see different results but I'm not entirely sure why. Could someone explain the difference between these two methods, and when it's more appropriate to use one over the other?

    Any real-world examples would also be helpful. Thanks

    Continue reading...

Compartilhe esta Página