Python string lstrip() method

Python String lstrip() Method

Description

Following is the syntax of the lstrip() method –

Syntax

var.lstrip([chars])

Parameters

  • chars – You can specify the characters to be stripped.

Return Value

This method returns a copy of the string with all characters removed from the beginning of the string (space characters are the default).

Example

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

var = " Hello Python "
var1 = var.lstrip()
print ("Original string:", var)
print ("String after removing left spaces:", var1)

var = "0001234000"
var2 = var.lstrip('0')
print ("Original string:", var)
print ("String after removing left zeros:", var2)

var = '''
Welcome To
TutorialsPoint
'''
var3 = var.lstrip()
print ("Original string:", var)
print ("String after removing left spaces:", var3)

When you run this program, the following output will be generated –

Original string: Hello Python
String after removing left spaces: Hello Python
Original string: 0001234000
String after removing left zeros: 1234000
Original string:
Welcome To
TutorialsPoint

String after removing left spaces: Welcome To
TutorialsPoint

Leave a Reply

Your email address will not be published. Required fields are marked *