• notice
  • Congratulations on the launch of the Sought Tech site

Write a Python program to remove substrings of a specific length from a given string

We need to write a Python program that will remove certain substrings from a given string


Step 1: Define a string.
Step 2:  Use  the  replace  function  to  remove the  substring  from  the given string.

sample code

original_string =  "C++ is an object oriented programming language" modified_string = original_string.replace( "object oriented" ,  "" )print(modified_string)

output result

C++  is  a programming language


The built-in Python replace() function takes the following arguments:

  • Oldstring: the string you want to remove

  • Newstring: The new string to replace the old string with

  • count: optional. the number of times you want to replace the old string with the new string


Technical otaku

Sought technology together

Related Topic


Leave a Reply