-
Notifications
You must be signed in to change notification settings - Fork 0
python vs js on split
fieldsfarmer edited this page Oct 11, 2016
·
2 revisions
JavaScript (Node.js v6.7.0)
var s = 'abc';
s.split(); // [ 'abc' ]
s.split(''); // [ 'a', 'b', 'c' ]
'hello world'.split(); // [ 'hello world' ]
'hello world'.split(' '); // [ 'hello', 'world' ]
''.split(); // [ '' ]
''.split(' '); // [ '' ]Python 2
s = 'abc'
s.split() # ['abc']
s.split('') # error! empty separator
list(s) # ['a', 'b', 'c']
'hello world'.split() # ['hello', 'world']
'hello world'.split(' ') # ['hello', 'world']
''.split() # []
''.split(' ') # ['']