Python Split String İnto List

1. str.split()

We can use str.split(sep=None) function which returns a list of the words in the string, using sep as the delimiter string.

For example, to split the string with delimiter -, we can do:

If sep is not specified or is None, runs of consecutive whitespace are regarded as a single separator.


2. shlex.split()

The shlex module defines the shlex.split(s) function which split the string s using shell-like syntax.