Replace String with another in Python

In order to do it, we will use Replace() method in Python:


replace() function:

In this example, we replace the string “World” with “LearnDuty” in the text variable a.

a = "Hello, World!"
print(a.replace("World", "LearnDuty"))

Output:

Hello, LearnDuty!

Bilel-A

Enthusiastic Network Engineer specializing in Cisco ACI, passionate about solving challenges. A lifelong learner who loves gaining and sharing knowledge. Profile: https://www.linkedin.com/in/bilel-ameur-71116b2b5
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x