[python] string.maketrans() 파이썬 문자열 치환함수

반응형


string.maketrans()

[정의]

문자열을 치환해 주는 함수. 숫자가능. 단, 바꾸기 전/후 문자의 길이가 같아야 한다.


[예시]

1
2
3
4
5
6
7
import string
 
obj = 'python'
before = 'thon'
after = 'zzzz'
sen = obj.maketrans(before, after)
print(obj.translate(sen))
cs


[결과]

1
2
pyzzzz
>>> 
cs


반응형

'Programing > python' 카테고리의 다른 글

python 파일 입출력  (0) 2017.03.21
linux에서 python 환경 구성하기  (0) 2017.03.20
python 정렬 알고리즘(선택/삽입/거품/합병)  (0) 2017.02.07
python 재귀함수  (0) 2017.02.07
python 모듈/패키지  (0) 2017.01.19
TAGS.

Comments