Split string by a space character in python

Python – Split String by Space

In this tutorial, we will look at how to split a string into a list of strings on the occurrences of a space character in Python with the help of examples.

How to split a string in Python?

Split string by a space character in python

You can use the Python string split() function to split a string (by a delimiter) into a list of strings. To split a string by space in Python, pass the space character " " as a delimiter to the split() function.

The following is the syntax –

# split string s by a space
s.split(" ")

It returns a list of strings resulting from splitting the original string on the occurrences of a single space, " ".

Let’s look at some examples.

Split string by Space

Here, we pass a single space character, " " as the delimiter to the string split() function.

# string with spaces
s = "Identity theft is not a joke."
# split string by a space
ls = s.split(" ")


['Identity', 'theft', 'is', 'not', 'a', 'joke.']

The resulting list contains words resulting from the split of the original string on occurrences of a space character.

📚 Data Science Programs By Skill Level


Intermediate ⭐⭐⭐

Advanced ⭐⭐⭐⭐⭐

🔎 Find Data Science Programs 👨‍💻 111,889 already enrolled

Disclaimer: Data Science Parichay is reader supported. When you purchase a course through a link on this site, we may earn a small commission at no additional cost to you. Earned commissions help support this website and its team of writers.

Fix the number of splits

You can also specify the maximum number of splits to be made using the maxsplit parameter. By default, the string split() function makes all the possible splits.

Let’s only split the above string into two parts at the occurrence of a space character, " "starting from the left. To split the string into two parts, the maxsplit should be 1, because we’re making only one split resulting in two strings.

# string with spaces
s = "Identity theft is not a joke."
# split string by a space
ls = s.split(" ", maxsplit=1)


['Identity', 'theft is not a joke.']

You can see that the resulting list has only two strings.

Let’s look at another example.

Let’s split the original string into three parts, here we pass maxsplit=2.

# string with spaces
s = "Identity theft is not a joke."
# split string by a space
ls = s.split(" ", maxsplit=2)


['Identity', 'theft', 'is not a joke.']

The resulting list has only three strings.

You might also be interested in –

  1. Python – Split String by Underscore
  2. Python – Remove Multiple Spaces From a String
  3. Remove Linebreaks From String in Python

Subscribe to our newsletter for more informative guides and tutorials.
We do not spam and you can opt out any time.


  • Piyush Raj

    Piyush is a data professional passionate about using data to understand things better and make informed decisions. He has experience working as a Data Scientist in the consulting domain and holds an engineering degree from IIT Roorkee. His hobbies include watching cricket, reading, and working on side projects.

Scroll to Top