In Python, “splitting a word” usually means one of two things. To break a word into its individual letters, use list(word), which turns "hello" into ['h', 'e', 'l', 'l', 'o']. To split a sentence or string into separate words, use the split() method: "split this text".split() returns ['split', 'this', 'text']. For other cases, such as splitting at a specific character, a fixed position, or several different separators, Python has slicing, partition(), and the re module.
Below are the most useful techniques, with short examples you can paste into Python to try.
Split a word into individual characters
word = "python"
letters = list(word)
print(letters) # ['p', 'y', 't', 'h', 'o', 'n']
list() walks through the string and puts each character into a list. You can do the same with a list comprehension, which is useful if you also want to transform each letter:
upper_letters = [ch.upper() for ch in "python"]
# ['P', 'Y', 'T', 'H', 'O', 'N']
You often don’t need a list at all, because strings are already iterable. A plain for ch in word: loop visits each character in order.
Split a string into words with split()
sentence = "Learning Python is fun"
words = sentence.split()
print(words) # ['Learning', 'Python', 'is', 'fun']
With no arguments, split() splits on any whitespace (spaces, tabs, and new lines) and ignores extra spaces, so "a b".split() gives ['a', 'b'].
Split on a specific separator
csv_line = "red,green,blue"
colors = csv_line.split(",")
print(colors) # ['red', 'green', 'blue']
When you pass a separator, Python splits exactly at each occurrence. Unlike the no-argument version, consecutive separators create empty strings: "a,,b".split(",") returns ['a', '', 'b'].
Limit the number of splits
path = "home/user/docs/file.txt"
print(path.split("/", 1)) # ['home', 'user/docs/file.txt']
print(path.rsplit("/", 1)) # ['home/user/docs', 'file.txt']
The second argument, maxsplit, stops after that many splits. rsplit() works the same way but starts from the right, which is handy for separating a file name from its folder.
Split a word at a position with slicing
word = "football"
first, second = word[:4], word[4:]
print(first, second) # foot ball
Slicing uses [start:end] indexes. It’s the simplest way to cut a word in half or take a fixed-length prefix or suffix. To split a word into chunks of equal size, combine slicing with range():
text = "abcdefgh"
chunks = [text[i:i+3] for i in range(0, len(text), 3)]
# ['abc', 'def', 'gh']
Split once around a separator with partition()
email = "[email protected]"
user, sep, domain = email.partition("@")
print(user, domain) # name example.com
partition() always returns three parts: the text before the separator, the separator itself, and the text after. If the separator isn’t found, the last two parts are empty strings, so it never raises an error.
Split on several separators with re.split()
import re
data = "apples; oranges, pears|plums"
items = re.split(r"[;,|]\s*", data)
print(items) # ['apples', 'oranges', 'pears', 'plums']
The re module splits on a regular expression, so one call can handle commas, semicolons, pipes, and spaces together.
Split text into lines
poem = "line one\nline two\nline three"
lines = poem.splitlines()
# ['line one', 'line two', 'line three']
splitlines() handles Windows (\r\n) and Unix (\n) line endings, which makes it safer than split("\n") for text files.
Which method should you use?
| Goal | Use |
|---|---|
| Letters of a word | list(word) |
| Words in a sentence | text.split() |
| Split at a character, such as a comma | text.split(",") |
| Only the first or last split | split(sep, 1) or rsplit(sep, 1) |
| At a fixed position | Slicing, word[:n] and word[n:] |
| Before and after one separator | partition() |
| Several different separators | re.split() |
| Lines of text | splitlines() |
Practical examples
Count the words in a sentence
len(text.split()) gives a quick word count. Because split() ignores repeated spaces and line breaks, the result stays accurate even for messy text pasted from a document or a web page.
Read numbers typed by a user
If someone types 3 7 12 into an input() prompt, [int(n) for n in input().split()] turns it into the list [3, 7, 12]. This pattern appears constantly in beginner exercises and coding challenges.
Get a file’s extension
"report.final.docx".rsplit(".", 1)[-1] returns "docx". Using rsplit with a limit of one means file names that contain extra dots still give the right answer. For real file paths, Python’s pathlib module, with Path(name).suffix, is even more reliable.
Check whether a word is a palindrome
You don’t need to split at all here: word == word[::-1] compares the word with its reversed slice. It’s a good reminder that slicing often replaces manual splitting when you only need to rearrange characters.
Joining the pieces back together
The opposite of splitting is join(). Call it on the separator you want between the pieces: "-".join(['a', 'b', 'c']) returns "a-b-c", and "".join(list("hello")) rebuilds the original word. Splitting and joining together are a common way to clean up text, for example " ".join(text.split()) collapses repeated spaces into one.
Common mistakes
- Calling split(“”) to get letters: An empty separator raises
ValueError. Uselist(word)instead. - Forgetting that strings don’t change:
split()returns a new list; the original string stays the same. - Unexpected empty strings: Use
split()with no argument, or filter with[w for w in parts if w]. - Unpacking the wrong number of parts:
a, b = text.split(",")fails if there aren’t exactly two pieces. Usemaxsplitorpartition().
Related: How to run a Python script in Windows.
Related: Fix the list assignment index out of range error in Python.
Related: Fixing “can’t multiply sequence by non-int” errors in Python.
Related: Avoid TypeError when formatting strings in Python.
Frequently asked questions
How do I split a string without removing the separator?
Use re.split() with a capturing group, such as re.split(r"(,)", text), which keeps the commas in the result.
Does split() work on numbers?
Only on strings. Convert first with str(number), then split, and convert the pieces back with int() if needed.

Kermit Matthews is a freelance writer based in Philadelphia, Pennsylvania with more than a decade of experience writing technology guides. He has a Bachelor’s and Master’s degree in Computer Science and has spent much of his professional career in IT management.
He specializes in writing content about iPhones, Android devices, Microsoft Office, and many other popular applications and devices.