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


Posted

in

Tags:

Comments

Leave a Reply