Answers for "replace ner with using python"

2

python how to replace a certain string in text

# Read in the file
with open('file.txt', 'r') as file :
  filedata = file.read()

# Replace the target string
filedata = filedata.replace('ram', 'abcd')

# Write the file out again
with open('file.txt', 'w') as file:
  file.write(filedata)
Posted by: Guest on August-14-2021
0

how to use replace in python

# Syntax - str.replace(old, new [, count]) 

song = 'cold, cold heart'
replaced_song = song.replace('o', 'e')


# The original string is unchanged
print('Original string:', song)

print('Replaced string:', replaced_song)

song = 'let it be, let it be, let it be'

# maximum of 0 substring is replaced
# returns copy of the original string
print(song.replace('let', 'so', 0))
Posted by: Guest on January-03-2022

Python Answers by Framework

Browse Popular Code Answers by Language