📜  Numpy字符串操作 | rindex()函数

📅  最后修改于: 2022-05-13 01:56:56.668000             🧑  作者: Mango

Numpy字符串操作 | rindex()函数

numpy.core.defchararray.rindex()函数,当找不到子字符串 sub 时引发 ValueError。按元素调用 str.rindex。

代码#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)


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)


输出 :

代码#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)

输出 :