Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

주어진 문자열에서 특정 길이의 부분 문자열을 제거하는 Python 프로그램을 작성하십시오.

<시간/>

주어진 문자열에서 특정 부분 문자열을 제거하는 Python 프로그램을 작성해야 합니다.

알고리즘

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

예시 코드

original_string = "C++ is a object oriented programming language"

modified_string = original_string.replace("object oriented", "")

print(modified_string)

출력

C++ is a  programming language

설명

빌드 내 Python replace() 함수는 다음 매개변수를 사용합니다.

  • Oldstring:제거하려는 문자열
  • Newstring:기존 문자열 대신 교체하려는 새 문자열
  • 개수:선택 사항입니다. 기존 문자열을 새 문자열로 교체하려는 횟수