Python split()

Last Updated : 6 Jan 2026

In Python, the split() method is used for splitting a string into several lists of strings. We can break the string with the help of a specified separator.

Python split()

Syntax

separator: The string that could be placed between items, also known as a delimiter.

maxsplit: It is the number that defines the number of times the strings must be split. -1 is the default value if no value is provided; it means that there is no limit.

Example: Split String

Compile and Run

Output:

['T', 'Point', 'Tech']

Splitting the String Using the split() Method

The split() method is a simple, reliable, and efficient method that enables us to divide a string into multiple lists of substrings based on a specified delimiter. The split method considers spaces like whitespaces, tabs, and newlines as points from where the strings will be separated.

Example: split() Method

Compile and Run

Output:

['Hello', 'Welcome', 'to', 'Tpoint', 'Tech', 'for', 'learning']

Let's see another example in which we will split the text consisting of newlines by using the same split() method. It considers newlines are whitespaces, which makes it a point from where the strings get separated.

Example: Splitting From New Lines or White Spaces

Compile and Run

Output:

['Hello', 'Welcome', 'to', 'Tpoint', 'Tech', 'to', 'learn', 'Python', 'Split']

Defining Number of Splits

Maxsplit is the number that defines the number of times the strings must be split. -1 is the default value if no value is provided; it means that there is no limit.

Example

Compile and Run

Output:

Maxsplit:0
 ['Welcome, to, T, Point, Tech']
Maxsplit:1
 ['Welcome', 'to, T, Point, Tech']
Maxsplit:2
 ['Welcome', 'to', 'T, Point, Tech']
Maxsplit:3
 ['Welcome', 'to', 'T', 'Point, Tech']
Maxsplit:4
 ['Welcome', 'to', 'T', 'Point', 'Tech']

As we can see, if we set maxsplit to 1, it divides into two distinct strings. If we set it to 4, it divides into four different parts.

Example: Maxsplit a String

Compile and Run

Output:

Laptop: LENOVO
Model: IDEAPAD-5
Price: 69999
Stock Status: In-Stock

We can also extract particular information, which means that we can access it individually.

Example: Accessing particular information

Compile and Run

Output:

The Price of the Laptop is:
69999

Split With Different Delimiters Using sep Delimiter

In Python, sep is a type of delimiter that is used to split the CSV (Comma-separated values) file string into multiple substrings. In CSV strings, every line represents a row, and every value which is in the line is separated by commas.

Example: Split Using Delimiter

Compile and Run

Output:

['Andrew', 'Tom', 'Jack', 'Herris', 'Denial']

Example: Splitting a String Using Delimiter

Compile and Run

Output:

['Laptop', 'Silver', '14 inch', 'In Stock']

We can also extract particular information, which means that we can access it individually.

Example: Accessing particular Information

Compile and Run

Output:

The size of the laptop is:
 14 inch

Split Strings by Lines

The splitlines() function is used in the case where there are multiple lines of strings and we need to split them into individual lines.

Example: splitlines() Function

Compile and Run

Output:

['Welcome to', 'T point Tech', ' for learning ', ' Python Splits']

Advantages of the splitlines() Function

  • It helps in reading the small files where we want to process the large piece of information line by line. This method enables the user to transform the entire content into a list of lines.
  • It plays an important role in processing the logs that contain multiple lines of text, which represent a distinct event or message.
  • This function can handle input of multiple lines by the user, as it can break down every statement easily and process it separately.

Conclusion

Let's conclude this tutorial by recapping what we learned. We learnt that the Python Split method is used for splitting a string into several list of strings. We can break the string with the help of a specified separator. We learnt about various methods, such as using the split() method, using maxsplit is the number which defines the number of times the strings must be split. We got to know about different delimiters like sep and functions like splitlines().