The lstrip() method will remove leading whitespaces, newline and tab characters on a string beginning:

>>> '     hello world!'.lstrip()
'hello world!'

Edit

As balpha pointed out in the comments, in order to remove only spaces from the beginning of the string, lstrip(' ') should be used:

>>> '   hello world with 2 spaces and a tab!'.lstrip(' ')
'\thello world with 2 spaces and a tab!'

Related question:

  • Trimming a string in Python
Answer from coobird on Stack Overflow
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-strip-trailing-whitespace-in-python
Trim a String in Python โ€“ How to Strip Trailing Whitespace
March 3, 2023 - Let's get into it! To trim a string and remove any whitespace, whether leading or trailing, use the strip() method. When the strip() method has no argument, it removes both leading and trailing whitespace from a string.
๐ŸŒ
DEV Community
dev.to โ€บ trinityyi โ€บ how-do-i-trim-whitespace-from-a-string-in-python-309o
How do I trim whitespace from a string in Python? - DEV Community
September 15, 2022 - Use the str.strip() method to remove whitespace characters from both the beginning and end of a string. ... Leading whitespace characters are the whitespace characters at the start of a string....
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-remove-spaces-from-string
Effective Ways to Remove Spaces from Strings in Python | DigitalOcean
July 11, 2025 - The strip() method is used to remove whitespace from the start and end of a string. For removing whitespace from the entire string, replace() can be used, and for more sophisticated patterns, you can use regular expressions via the re module. When using print() with multiple arguments, Python ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-strip-how-to-trim-a-string-or-line
Python strip() โ€“ How to Trim a String or Line
January 12, 2022 - When the .strip() method has no argument, it removes any leading and/or trailing whitespace from a string. So, if you have whitespace at the start and/or end of a word or phrase, .strip() alone, by default, will remove it.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-remove-spaces-from-a-string
Remove spaces from a string in Python - GeeksforGeeks
Explanation: s.strip() removes spaces from the start and end of s. If we only want to remove spaces from the beginning of the string, we can use lstrip().
Published ย  July 11, 2025
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-strip-remove-white-spaces-start-end-string
Trim white spaces from String in Python
In this tutorial, we will go through examples that demonstrate how to use String.strip() function to trim whitespaces from a given string. In the following example, we assign a variable with a string that has spaces at start and end of it. Then we use strip() function to remove the spaces around ...
Find elsewhere
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-trim
How to Trim a String in Python: Three Different Methods | DataCamp
February 16, 2025 - Python provides built-in methods to trim strings, making it straightforward to clean and preprocess textual data. These methods include ยท .strip(): Removes leading and trailing characters (whitespace by default).
๐ŸŒ
ItSolutionstuff
itsolutionstuff.com โ€บ post โ€บ python-remove-whitespace-from-start-and-end-of-string-exampleexample.html
Python Remove Whitespace from Start and End of String Example - ItSolutionstuff.com
October 30, 2023 - We will use python remove whitespace beginning and end. In this example, I will add myString variable with hello string. Then we will use strip() function to whitespace from start and end of string in python.
๐ŸŒ
Medium
geekpython.medium.com โ€บ ways-to-remove-whitespaces-from-the-string-in-python-f1e1481a9c33
Ways To Remove Whitespaces From The String In Python | by Sachin Pal | Medium
July 29, 2022 - It removes the leading and trailing ... method removed the leading and the trailing whitespace from the my_str. Python replace() function removes all the whitespace characters from the string including whitespace between words ...
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ python-strip
Python strip() Function Guide (With Examples)
December 5, 2023 - The strip() method in Python is straightforward to use. Itโ€™s a built-in function that operates on string data types. Its primary purpose is to remove leading (spaces at the start) and trailing (spaces at the end) whitespace from a string.
๐ŸŒ
Net Informations
net-informations.com โ€บ python โ€บ pro โ€บ space.htm
How to remove spaces from a string in Python
For the purpose of removing leading and trailing spaces within a string, the strip() method serves as the appropriate tool. This function effectively trims the whitespace from both the start and end of the string, resulting in a cleaner and more focused textual representation.
๐ŸŒ
W3Schools
w3schools.com โ€บ PYTHON โ€บ ref_string_strip.asp
Python String strip() Method
Python Examples Python Compiler ... Plan Python Interview Q&A Python Bootcamp Python Training ... The strip() method removes any leading, and trailing whitespaces. Leading means at the beginning of the string, trailing means at ...
๐ŸŒ
30 Seconds of Code
30secondsofcode.org โ€บ home โ€บ python โ€บ trim whitespace
How do I trim whitespace from a string in Python? - 30 seconds of code
December 13, 2021 - Use the str.strip() method to remove whitespace characters from both the beginning and end of a string. ... Leading whitespace characters are the whitespace characters at the start of a string....
๐ŸŒ
Codedamn
codedamn.com โ€บ news โ€บ python
Python Strip Whitespace: A Complete Guide
July 3, 2023 - The output will be: 'codedamn is awesome!!!'. The strip('') function removed all the asterisks () from the beginning and end of the string. 1. Can Python strip functions remove all whitespaces in a string?
๐ŸŒ
Statistics Globe
statisticsglobe.com โ€บ home โ€บ python programming language for statistics & data science โ€บ how to remove whitespace from python string | 5 examples (strip, rstrip & lstrip)
Remove Whitespace From Python String | 5 Examples (strip, rstrip & lstrip)
March 16, 2022 - Thatโ€™s what Iโ€™m going to show you in Example 2 and 3! With the Python strip function, we were able to delete all left and right spaces (as shown in Example 1). However, sometimes you might want to keep the whitespace at the beginning and ...
๐ŸŒ
CodeFatherTech
codefather.tech โ€บ home โ€บ blog โ€บ how do you remove spaces from a python string?
How Do You Remove Spaces From a Python String? - CodeFatherTech
June 27, 2025 - There are multiple ways to remove spaces from a Python string. The simplest approach is to use the string replace() method. If the spaces to remove are just at the beginning and at the end of the string the strip() method also works fine. An alternative approach is to use a regular expression.
๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ python-trim
Python Trim: How to Trim a Whitespace from a String in Python - Flexiple - Flexiple
March 11, 2022 - To specifically target and remove leading whitespace, the .lstrip() method is used. This function trims spaces at the start of a string, making it particularly useful when preparing strings for further processing that requires a clean start.
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ remove-spaces
How to remove spaces in Python - Python Morsels
January 25, 2022 - Need to remove all spaces from a string in Python? If it's just space characters you could use the string replace method to replace all spaces by an empty string. If we call the replace method on this greeting string: >>> greeting = " Hello world!