기본적으로 python에 replace 함수 인자값 구조는 이렇습니다.
1. 이전 문자열 (필수값)
2. 새로운 문자열 (필수값)
3. 변경횟수 (옵션, 기본은 전체)
예시 (replace one)
s = '홍2길동2'
s = s.replace('2', '', 1)
print(s)
결과
홍길동2
예시 (replace all)
s = '홍2길동2'
s = s.replace('2', '')
print(s)
결과
홍길동
참조
[w3 python]: https://www.w3schools.com/python/ref_string_replace.asp
Python String replace() Method
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
www.w3schools.com
728x90
'Programing Language > Python' 카테고리의 다른 글
[Python] Snake Case To Camel Case ( str, dict, list ) (0) | 2023.05.30 |
---|---|
[Python] pydantic.error_wrappers.ValidationError (0) | 2023.05.21 |
[Python] 문자열을 날짜 또는 시간으로 변환 (Convert String to Date or Time) (0) | 2023.05.20 |
[Python] try except 예외 처리 (Exception) (0) | 2023.05.17 |
[Python] Json 관련 (dumps , loads) (0) | 2023.05.14 |
댓글