Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
numpy
python
communitycreator

What is the numpy.char.rstrip() function 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.rstrip() function in Python is used to return an array wherein the ending or trailing characters of the input array are removed.

Syntax

char.rsplit(a, char)

Parameter value

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

  • a: This is the input array of strings or Unicode.
  • char: This is the character(s) that needs to be removed.

Return value

The char.strip() function returns an output array of strings or Unicodes, depending on the input type in the function.

Code example

import numpy as np

# creating an array 
myarray = np.array(["That", "Hat", "Pat"])

# implementing the char.lstrip() function to remove `at`
print(np.char.rstrip(myarray, "at"))
Implementing the char.rstrip() 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.rstrip() function on myarray by removing the ending set of characters, "at", from the element of the array. Then, we print the result to the console.

RELATED TAGS

function
numpy
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