Skip to content
Related Articles
Open in App
Not now

Related Articles

Numpy string operations | rindex() function

Improve Article
Save Article
Like Article
  • Last Updated : 29 Aug, 2020
Improve Article
Save Article
Like Article

 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

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!