Difference Between strip and split in Python Last Updated : 13 Nov, 2024 Comments Improve Suggest changes Like Article Like Report The major difference between strip and split method is that strip method removes specified characters from both ends of a string. By default it removes whitespace and returns a single modified string. Whereas, split method divides a string into parts based on a specified delimiter and by default it splits by whitespace and returns a list of strings.Example of strip() Python s = " hello world " # Removes spaces from both ends print(s.strip()) s1 = "***hello***" # Removes asterisks from both ends print(s1.strip("*")) Outputhello world hello Explanation: s.strip() removes spaces from both beginning and end of the string and results in "hello world".strip("*") removes * characters from both ends and results in "hello".Example of split() Python s = "hello world" # Splits by whitespace print(s.split()) s1 = "apple,orange,banana" # Splits by comma print(s1.split(',')) Output['hello', 'world'] ['apple', 'orange', 'banana'] Explanation: s.split() basically splits "hello world" into two elements based on whitespace and results in ['hello', 'world']split(',') divides string at each comma and results in list ['apple', 'orange', 'banana'] Comment More infoAdvertise with us Next Article Difference Between strip and split in Python chinmoy lenka Follow Improve Article Tags : Python Python-Built-in-functions python-string Practice Tags : python Similar Reads Difference between end and sep in Python In this article we will discuss the difference between The end and sep are two parameters in Python's built-in print() function that will help to control how the output is formatted. end in PythonThe end is a parameter in Python's built-in print() function that controls what character(s) are printed 2 min read Difference between / vs. // operator in Python In Python, both / and // are used for division, but they behave quite differently. Let's dive into what they do and how they differ with simple examples./ Operator (True Division)The / operator performs true division.It always returns a floating-point number (even if the result is a whole number).It 2 min read Difference Between Del, Remove and Pop in Python Lists del is a keyword and remove(), and pop() are in-built methods in Python. The purpose of these three is the same but the behavior is different. remove() method deletes values or objects from the list using value and del and pop() deletes values or objects from the list using an index.del Statementdel 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:Pythons = "geeks,for,geeks" # Split the string by commas res = s.split(',') # Parse the list and print each element for item in res: print(item)Outputgeeks for g 2 min read How to Index and Slice Strings in Python? In Python, indexing and slicing are techniques used to access specific characters or parts of a string. Indexing means referring to an element of an iterable by its position whereas slicing is a feature that enables accessing parts of the sequence.Table of ContentIndexing Strings in PythonAccessing 2 min read Split a string on multiple delimiters in Python In this article, we will explore various methods to split a string on multiple delimiters in Python. The simplest approach is by using re.split().Using re.split()The re.split() function from the re module is the most straightforward way to split a string on multiple delimiters. It uses a regular exp 2 min read 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 How to Split a File into a List in Python In this article, we are going to see how to Split a File into a List in Python. When we want each line of the file to be listed at consecutive positions where each line becomes an element in the file, the splitlines() or rstrip() method is used to split a file into a list. Let's see a few examples 5 min read Python | Pandas Series.str.strip(), lstrip() and rstrip() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages that makes importing and analyzing data much easier. Pandas provide 3 methods to handle white spaces(including New lines) in any text data 4 min read Like