PYTHON 프로그래밍

본문 바로가기
사이트 내 전체검색


PYTHON 프로그래밍
PYTHON 프로그래밍

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

페이지 정보

작성자 관리자 댓글 0건 조회 3,095회 작성일 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

'''

댓글목록

등록된 댓글이 없습니다.


개인정보취급방침 서비스이용약관 모바일 버전으로 보기 상단으로

TEL. 063-469-4551 FAX. 063-469-4560 전북 군산시 대학로 558
군산대학교 컴퓨터정보공학과

Copyright © www.leelab.co.kr. All rights reserved.