Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

Python lstrip

by suresh

The Python lstrip method is a Python String Methods, which is useful to remove the specified characters from the Left-hand side of a string. By default, the Python lstrip function deletes white spaces and returns a new string.

The syntax of the Python lStrip function is

String_Value.lstrip(Chars)
  • String_Value: A valid String literal.
  • Chars: This parameter is optional, and Omit this means the lstrip function considers the white spaces as a default parameter. To change the default white space, specify the Characters to strip from the Left-hand side of a string in Python.

Python lstrip method Example

The following set of examples helps to know the lstrip Function.

# Python lStrip Method Example

Str1 = '  Tutorial Gateway'

Str2 = Str1.lstrip()
print('Stripping Whitespaces on Left using lStrip() is =', Str2)

# Observe the Original String
print('Converted String is =', Str1.lstrip())
print('Original String is =', Str1)

# Performing lStrip() function directly
Str3 = '00000000Tutorial Gateway00000000'.lstrip('0')
print("Stripping 0's on Left using lStrip() is =", Str3)

# Stripping Left Side
Str4 = '+++++*********Tutorial Gateway'.lstrip('+*')
print('Stripping + and * on Left using lStrip() is =', Str4)

OUTPUT

ANALYSIS

Here, we declared a String variable Str1 and assigned a text value

Str1 = '  Tutorial Gateway'

The below statement removes the empty spaces from the Left-hand side of String variable Str1 using lStrip function and prints the output.

Str2 = Str1.lstrip()
print('Stripping Whitespaces on Left using LStrip() is =', Str2)

The lStrip function in Python returns the output in a new string.

print('Converted String is =', Str1.lstrip())
print('Original String is =', Str1)

To modify the original String, write this lstrip statement

Str1 = Str1.lstrip()

The Python lstrip function only removes the specified characters from the left side of a string and omit right-hand side characters. Within the next String function statements, we have zeros on both sides. Moreover, see the above image that the lstrip function output is removing zeros from the Left-hand side only.

Str3 = '00000000Tutorial Gateway00000000'.lstrip('0')
print("Stripping 0's on Left using LStrip() is =", Str3)

in this Python statement, we used two characters to strip (+ and *) from the Left-hand side.

Str4 = '+++++*********Tutorial Gateway'.lstrip('+*')
print('Stripping + and * on Left using LStrip() is =', Str4)

Placed Under: Python

  • Download and Install Python
  • Python Arithmetic Operators
  • Python Assignment Operators
  • Python Bitwise Operators
  • Python Comparison Operators
  • Python Logical Operators
  • Python If Statement
  • Python If Else
  • Python Elif Statement
  • Python Nested If
  • Python For Loop
  • Python While Loop
  • Python Break
  • Python Continue
  • Python Dictionary
  • Python datetime
  • Python String
  • Python Set
  • Python Tuple
  • Python List
  • Python List Comprehensions
  • Python Lambda Function
  • Python Functions
  • Python Types of Functions
  • Python Iterator
  • Python File
  • Python Directory
  • Python Class
  • Python classmethod
  • Python Inheritance
  • Python Method Overriding
  • Python Static Method
  • Connect Python and SQL Server
  • Python SQL Create DB
  • Python SQL Select Top
  • Python SQL Where Clause
  • Python SQL Order By
  • Python SQL Select Statement
  • Python len Function
  • Python max Function
  • Python map Function
  • Python print Function
  • Python sort Function
  • Python range Function
  • Python zip Function
  • Python Math Functions
  • Python String Functions
  • Python List Functions
  • Python NumPy Array
  • NumPy Aggregate Functions
  • NumPy Arithmetic Operations
  • Python Numpy Bitwise operators
  • Numpy Comparison Operators
  • Numpy Exponential Functions
  • Python Numpy logical operators
  • Python Numpy String Functions
  • NumPy Trigonometric Functions
  • Python random Array
  • Python Numpy concatenate
  • Python Numpy Array shape
  • Python Pandas DataFrame
  • Pandas DataFrame plot
  • Python Series
  • Python matplotlib Histogram
  • Python matplotlib Scatter Plot
  • Python matplotlib Pie Chart
  • Python matplotlib Bar Chart
  • Python List Length
  • Python sort List Function
  • Python String Concatenation
  • Python String Length
  • Python Substring
  • Python Programming Examples
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy