replace() 메서드는 지정된 구문을 다른 지정된 구문으로 바꿉니다.
주의: 다른 항목이 지정되지 않은 경우 지정된 구문이 모두 바뀝니다.
매개변수 | 필수 | 설명 |
---|---|---|
oldvalue | 필수 | 검색할 문자열 |
newvalue | 필수 | 이전 값을 대체할 문자열 |
count | 선택 | 얼마나 많은 oldvalue를 바꿀지 지정하는 숫자입니다. 기본값은 모든 항목입니다. |
지정된 구문을 다른 지정된 구문으로 바꾼 결과를 리턴합니다.
txt = "I like bananas" x = txt.replace("bananas", "apples") print(x)
결과
I like apples
txt = "one one was a race horse, two two was one too." x = txt.replace("one", "three") print(x)
결과
three three was a race horse, two two was three too.
© 2022 pinfo. All rights reserved.