Reputation: 543
According to python documentation.
str.split([sep[, maxsplit]])
If sep is not specified or is None, a different splitting algorithm is applied: runs of consecutive whitespace are regarded as a single separator, and the result will contain no empty strings at the start or end if the string has leading or trailing whitespace. Consequently, splitting an empty string or a string consisting of just whitespace with a None separator returns [].
But,
str = 'L1 \nL2 \nL3'
print str.split()
returns ['L1','L2','L3']
Upvotes: 1
Views: 70
Reputation: 17339
Whitespace consists of the characters ' '
, '\t'
, '\r'
, and '\n'
. Therefore, " \n"
is a single run of consecutive whitespace.
Upvotes: 9