replace() 문자열 제거, 수정 > PYTHON 프로그래밍

본문 바로가기

PYTHON 프로그래밍

PYTHON 프로그래밍

6. replace() 문자열 제거, 수정

페이지 정보

작성자 관리자 댓글 0건 조회 6,250회 작성일 20-07-20 00:09

본문

6. replace() 문자열 제거, 수정

문자열 변경(replace)



파이썬은 문자열 변경을 할 수 있는 replace 함수를 제공합니다.


replace와 replaceAll이 나눠져있는 자바와 혼동될 때가 있어서 메모합니다.


replace()의 사용 방법은 아래와 같습니다.



replace(old, new, [count]) -> replace("찾을값", "바꿀값", [바꿀횟수])



text = '123,456,789,999'


replaceAll= text.replace(",","")

replace_t1 = text.replace(",", "",1)

replace_t2 = text.replace(",", "",2)

replace_t3 = text.replace(",", "",3)

print("결과 :")

print(replaceAll)

print(replace_t1)

print(replace_t2)

print(replace_t3)


'''

결과 : 

123456789999

123456,789,999

123456789,999

123456789999

'''


Copyright © LEELAB.CO.KR. All rights reserved.