[Python] Split vs Strip in Python to remove redundant white space

Discussão em 'Python' iniciado por Stack, Maio 15, 2025.

  1. Stack

    Stack Membro Participativo

    Do I need to use strip() before split() to remove any redundant space in Python (and turn into a list after)? For example:

    string1 = ' a b '


    I want the result:

    list1 = ['a', 'b']


    When I test I found out that list1=string1.split() is enough. But somehow my teacher says string1.strip().split() is needed.

    Continue reading...

Compartilhe esta Página