Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

What is the numpy.char.lstrip() function from NumPy in Python?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The char.lstrip() function in Python is used to remove the leading characters of each element of an array of strings.

Syntax

numpy.char.lstrip(a, chars = None)

Function parameters

The char.lstrip() function takes the following parameter values:

  • a: This represents the input array of strings or unicode.
  • chars: This represents the particular set of characters that need to be removed from the input array of strings. This parameter value is optional.

Return value

The char.lstrip() function returns an array of strings or Unicode, depending on the type of the input in the input array.

Code example

import numpy as np
# creating an array
myarray = np.array(["hello", "hey! ,", "hey yO"])
# implementing the char.lstrip() function to remove `eo`
print(np.char.lstrip(myarray, "he"))
Implementing the "char.lstrip()" function

Code Explanation

  • Line 1: We import the numpy module.
  • Line 4: We create an array called myarray, using the array() function.
  • Line 7: We implement the char.lstrip() function on the array myarray by removing the starting set of characters, "he", from the element of the array. Then, we print the result to the console.

RELATED TAGS

python
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring