Python String lstrip method with Example – Python Tutorial

1 year ago Lalit Bhagtani 0

 In this tutorial, we will learn about python string lstrip method.
Python String lstrip

lstrip method :

This method returns a copy of the string in which all the occurrences of chars ( passed as an argument ) has been removed from the beginning ( left side ) of the string object on which method is called. If chars arguments is omitted or None, then chars argument defaults to whitespace.

Syntax : < String Object >.lstrip( [ chars ] ) :  < String Object >

              chars: characters to be removed.

Example:

[datacamp_exercise lang=”python” height=”400″ min-height=”300″ max-height=”500″]
[datacamp_pre_exercise_code]

[/datacamp_pre_exercise_code]
[datacamp_sample_code]
# create one string and assign it to variable s1
s1 = ‘ lstrip example’

# call lstrip() method on string s1
output = s1.lstrip()

# print the value of variable output
print(output)

# create one string and assign it to variable s2
s2 = ‘lstrip example’

# call lstrip() method on string s2 by passing ‘l’ as an argument
output = s2.lstrip(‘l’)

# print the value of variable output
print(output)
[/datacamp_sample_code]
[datacamp_solution]

[/datacamp_solution]
[/datacamp_exercise]

References :-

  1. lstrip() method Docs

That’s all for Python String lstrip method. If you liked it, please share your thoughts in comments section and share it with others too.

Previous