Open In App

Numpy string operations | rindex() function

Last Updated : 29 Aug, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

 numpy.core.defchararray.rindex() function, raises ValueError when the substring sub is not found. Calls str.rindex element-wise.

Syntax : numpy.core.defchararray.rindex(arr, sub, start = 0, end = None)

Parameters :

arr : [array-like of str or unicode]  Array-like of str .

sub : [str or unicode] Input string or unicode.

start, end : [int, optional] Optional arguments start and end are interpreted as in slice notation.

Return : Return the output array of ints.

Code #1 :  

Python3
# Python program explaining 
# numpy.char.rindex() function 

# importing numpy as geek  
import numpy as geek 

arr = "GeeksforGeeks - A computer science portal for geeks"
sub = 'science'

gfg = geek.char.rindex(arr, sub)
  
print (gfg)

Output :  

27

Code #2 :  

Python3
# Python program explaining 
# numpy.char.rindex() function 

# importing numpy as geek  
import numpy as geek 

arr = "GeeksforGeeks - A computer science portal for geeks"
sub = 'geeks'

gfg = geek.char.rindex(arr, sub, start = 0, end = None)
  
print (gfg)

Output : 

46


Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy