Python String lstrip() Method


Contents

Description

The lstrip() method in Python String returns a copy of the string where all the chars have been stripped right from the beginning of the string where whitespace characters are the default. The lstrip() method in Python string returns a copy of the string where the leading characters are removed (depending on the string argument that has been passed). The lstrip() method removes the characters from the left based upon the argument which is a string that specifies the set of characters that are to be removed.

Syntax

Following is the syntax for lstrip() method:

str.lstrip([chars])

Parameters

  • chars − You can supply what chars have to be trimmed.

Return Value

This method is responsible for returning a copy of the string where all the chars have been stripped right from the starting of the string with default whitespace characters.

Example

The following example shows the usage of lstrip() method.

#!/usr/bin/python

str = "     this is string example....wow!!!     ";
print str.lstrip()
str = "88888888this is string example....wow!!!8888888";
print str.lstrip('8')

When we run above program, it produces following result:

this is string example....wow!!!
this is string example....wow!!!8888888

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.



Navigation
Tutorial
Tutorial
Tutorial