Skip to content

38. What is the difference between split() and slicing in Python?

Both split() function and slicing work on a String object. By using split() function, we can get the list of words from a String.

E.g. 'a b c '.split() returns [‘a’, ‘b’, ‘c’] Slicing is a way of getting substring from a String. It returns another String. E.g. >>> 'a b c'[2:3] returns b