69 of 151 menu

The lstrip method

The lstrip method returns a string with the specified characters removed from the beginning. In the optional parameter of the method, we specify the characters we want to remove. If they are not specified, the method will only remove spaces at the beginning of the string.

Syntax

string.lstrip([characters to delete])

Example

Let's apply the lstrip method to the following line:

txt = 'abcdea' print(txt.lstrip('a'))

Result of code execution:

'bcdea'

Example

Let's put spaces at the beginning and end of the string and apply the lstrip method again:

txt = ' abcdea ' print(txt.lstrip('a'))

Since the first character of the string is now a space rather than the specified 'a', the method will simply return the original string if it finds no matches:

' abcdea '

Example

Now let's apply the lstrip method without specifying the parameter:

txt = ' abcdea ' print(txt.lstrip())

Result of code execution:

'abcdea '

See also

  • method strip,
    which removes characters from the beginning and end of a string
  • method rstrip,
    which removes characters from the end of a line
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline