- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a Python program to remove a certain length substring from a given string
We need to write a Python program which will remove a certain substring from a given string
Algorithm
Step 1: Define a string. Step 2: Use the replace function to remove the substring from the given string.
Example Code
original_string = "C++ is a object oriented programming language"
modified_string = original_string.replace("object oriented", "")
print(modified_string)
Output
C++ is a programming language
Explanation
The in-build Python replace() function takes the following parameters:
- Oldstring: The string which you want to remove
- Newstring: The new string you want to replace in place of the oldstring
- Count: Optional. Number of times you want to replace the oldstring with the newstring
Advertisements
To Continue Learning Please Login
Login with Google