bummi
0
Q:

replace() python

string.replace(old, new, count)
# Only return a copy, not modifying the string
25
# Python3 program to demonstrate the  
# use of replace() method   
  
string = "geeks for geeks geeks geeks geeks" 
   
# Prints the string by replacing geeks by Geeks  
print(string.replace("geeks", "Geeks"))  
  
# Prints the string by replacing only 3 occurrence of Geeks   
print(string.replace("geeks", "GeeksforGeeks", 3)) 
4
string = "[Message]"
string = string.replace("[", "")#Removes all [
string = string.replace("]", "")#Removes all ]

print(string)
1
# Simple replacement
str.replace(old, new, count)

# Multi-match replacement
import re
STRING = re.sub("(\.fasta|\.fna)","", STRING)
1
#our text
text='Hello! there/ how may. I help, you' #yes, it seems weird
     #replacing ("THIS" with "THIS") 
replaced_text=text.replace("!", "?")
print(replaced_text)
#output
#Hello? there/ how may. I help, you
0

New to Communities?

Join the community