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

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

Numpy字符串操作 |替换()函数

numpy.core.defchararray.replace()函数中,arr 中的每个元素返回字符串的副本,其中所有出现的子字符串 old 都替换为 new。

代码#1:

Python3
# Python program explaining 
# numpy.char.replace() function 
  
# importing numpy as geek  
import numpy as geek 
  
gfg = geek.char.replace('GFG | a computer science portal for geeks', 'GFG', 'GeeksforGeeks')
    
print (gfg)


Python3
# Python program explaining 
# numpy.char.replace() function 
  
# importing numpy as geek  
import numpy as geek 
  
gfg = geek.char.replace('This is a python article', 'python', 'Numpy-Python', count = 1)
    
print (gfg)


输出 :

代码#2:

Python3

# Python program explaining 
# numpy.char.replace() function 
  
# importing numpy as geek  
import numpy as geek 
  
gfg = geek.char.replace('This is a python article', 'python', 'Numpy-Python', count = 1)
    
print (gfg)

输出 :