0

I'm working with this code to learn about passing parameters into split(). If I pass "?" into the call to split() on the string y, it's splitting them into a list as you would expect, but it's adding an additional empty string right at the end. This applies whether there is one or more '?' in the string (3 in the example string below.

Can anyone tell me why it's doing this?

It doesn't seem to do this if I pass in a character like 's'.

    y = "Is this a sentence? And is this one? Hm?"
    z = y.split("?")
    print(len(z))
    print(z)
    for w in z:
        print(w)

This is the output:

4
['This is a sentence', ' And is this one', ' Hm', '']
This is a sentence
 And is this one
 Hm
Jules_ewls
  • 117
  • 1
  • 9

0 Answers0