Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Split and Parse a string in Python
Next article icon

Python String split()

Last Updated : 02 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Python String split() method splits a string into a list of strings after breaking the given string by the specified separator.

Example:

Python
string = "one,two,three" words = string.split(',') print(words) 

Output:

['one', 'two', 'three']

Python String split() Method Syntax

Syntax: str.split(separator, maxsplit)

Parameters

  • separator: This is a delimiter. The string splits at this specified separator. If is not provided then any white space is a separator.
  • maxsplit: It is a number, that tells us to split the string into a maximum of the provided number of times. If it is not provided then the default is -1 which means there is no limit.

Returns

Returns a list of strings after breaking the given string by the specified separator.

What is the list split() Method?

split() function operates on Python strings, by splitting a string into a list of strings. It is a built-in function in Python programming language.

It breaks the string by a given separator. Whitespace is the default separator if any separator is not given. 

How to use list split() method in Python?

Using the list split() method is very easy, just call the split() function with a string object and pass the separator as a parameter. Here we are using the Python String split() function to split different Strings into a list, separated by different characters in each case.

Example: In the above code, we have defined the variable ‘text’ with the string ‘geeks for geeks’ then we called the split() method for ‘text’ with no parameters which split the string with each occurrence of whitespace.

Python
text = 'geeks for geeks'  # Splits at space print(text.split())  word = 'geeks, for, geeks'  # Splits at ',' print(word.split(','))  word = 'geeks:for:geeks'  # Splitting at ':' print(word.split(':'))  word = 'CatBatSatFatOr'  # Splitting at t print(word.split('t')) 

Similarly, after that, we applied split() method on different strings with different delimiters as parameters based on which strings are split as seen in the output.


Output
['geeks', 'for', 'geeks'] ['geeks', ' for', ' geeks'] ['geeks', 'for', 'geeks'] ['Ca', 'Ba', 'Sa', 'Fa', 'Or']

How does split() work when maxsplit is specified?

The maxsplit parameter is used to control how many splits to return after the string is parsed. Even if there are multiple splits possible, it’ll only do maximum that number of splits as defined by the maxsplit parameter.

Example: In the above code, we used the split() method with different values of maxsplit. We give maxsplit value as 0 which means no splitting will occur.

Python
word = 'geeks, for, geeks, pawan'  # maxsplit: 0 print(word.split(', ', 0))  # maxsplit: 4 print(word.split(', ', 4))  # maxsplit: 1 print(word.split(', ', 1)) 

The value of maxsplit 4 means the string is split at each occurrence of the delimiter, up to a maximum of 4 splits. And last maxsplit 1 means the string is split only at the first occurrence of the delimiter and the resulting lists have 1, 4, and 2 elements respectively.


Output
['geeks, for, geeks, pawan'] ['geeks', 'for', 'geeks', 'pawan'] ['geeks', 'for, geeks, pawan']

How to Parse a String in Python using the split() Method?

In Python, parsing strings is a common task when working with text data. String parsing involves splitting a string into smaller segments based on a specific delimiter or pattern. This can be easily done by using a split() method in Python.

Python
text = "Hello geek, Welcome to GeeksforGeeks."  result = text.split() print(result) 

Explanation: In the above code, we have defined a string ‘text’ that contains a sentence. By calling the split() method without providing a separator, the string is split into a list of substrings, with each word becoming an element of the list.


Output
['Hello', 'geek,', 'Welcome', 'to', 'GeeksforGeeks.']

Hope this tutorial on the string split() method helped you understand the concept of string splitting. split() method in Python has various applications like string parsing, string extraction, and many more. “How to split in Python?” is a very important question for Python job interviews and with this tutorial we have answered the question for you.

Check More: String Methods 

For more informative content related to the Python string split() method you can check the following article:

  • Python program to split and join a string
  • Split and Parse a string in Python
  • Python | Ways to split a string in different ways
  • Python | Split string into list of characters


Next Article
Split and Parse a string in Python
author
pawan_asipu
Improve
Article Tags :
  • Python
  • python-string
Practice Tags :
  • python

Similar Reads

  • Python String rsplit() Method
    Python String rsplit() method returns a list of strings after breaking the given string from the right side by the specified separator. It's similar to the split() method in Python, but the difference is that rsplit() starts splitting from the end of the string rather than from the beginning. Exampl
    3 min read
  • String Slicing in Python
    String slicing in Python is a way to get specific parts of a string by using start, end and step values. It’s especially useful for text manipulation and data parsing. Let’s take a quick example of string slicing: [GFGTABS] Python s = "Hello, Python!" print(s[0:5]) [/GFGTABS]OutputHello Ex
    4 min read
  • Python String splitlines() method
    In Python, the splitlines() method is used to break a string into a list of lines based on line breaks. This is helpful when we want to split a long string containing multiple lines into separate lines. The simplest way to use splitlines() is by calling it directly on a string. It will return a list
    2 min read
  • Split and Parse a string in Python
    In this article, we'll look at different ways to split and parse strings in Python. Let's understand this with the help of a basic example: [GFGTABS] Python s = "geeks,for,geeks" # Split the string by commas res = s.split(',') # Parse the list and print each element for item in res
    2 min read
  • Python String rpartition() Method
    String rpartition() method in Python is a powerful tool for splitting a string into three parts, based on the last occurrence of a specified separator. It provides an efficient way to handle text parsing when we want to divide strings from the rightmost delimiter. Let us start with a simple example:
    4 min read
  • Python List Slicing
    Python list slicing is fundamental concept that let us easily access specific elements in a list. In this article, we’ll learn the syntax and how to use both positive and negative indexing for slicing with examples. Example: Get the items from a list starting at position 1 and ending at position 4 (
    5 min read
  • Python - Regex split()
    re.split() method in Python is generally used to split a string by a specified pattern. Its working is similar to the standard split() function but adds more functionality. Let’s start with a simple example of re.split() method: [GFGTABS] Python import re s = "Geeks,for,Geeks" # Using re.s
    3 min read
  • numpy string operations | split() function
    numpy.core.defchararray.split(arr, sep=None, maxsplit=None) is another function for doing string operations in numpy.It returns a list of the words in the string, using sep as the delimiter string for each element in arr. Parameters: arr : array_like of str or unicode.Input array. sep : [ str or uni
    2 min read
  • numpy string operations | rsplit() function
    numpy.core.defchararray.rsplit(arr, sep=None, maxsplit=None) is another function for doing string operations in numpy. It returns a list of the words in the string, using sep as the delimiter string for each element in arr. The rsplit() method splits every string array element into a list, starting
    2 min read
  • Python String strip() Method
    strip() method in Python removes all leading and trailing whitespace by default. You can also specify a set of characters to remove from both ends. It returns a new string and does not modify the original. Let's take an example to remove whitespace from both ends of a string. [GFGTABS] Python s =
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences