1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Strings and lists

Discussão em 'Python' iniciado por Stack, Outubro 3, 2024 às 08:52.

  1. Stack

    Stack Membro Participativo

    If we assign some string value to variable and the value of to variable , and then add something to variable , then variable will not change. But this trick won't work with lists:

    x = '0'
    y = x
    x += '0'
    print(y) # 0
    ##
    x = [0]
    y = x
    x += [0]
    print(*y) # 0 0


    This is because lists are actually references to real lists. But how do you make strings behave like lists, and lists behave like strings?

    How to do this by creating your own new_str and new_list classes?

    Continue reading...

Compartilhe esta Página