파이썬 번역 () 메소드
기술
파이썬은 델 매개 변수에 문자를 필터링 (256 자) 문자열 변환 표에 주어진 () 메서드 매개 변수 테이블을 번역합니다.
문법
() 메서드 구문을 번역 :
str.translate(table[, deletechars]);
매개 변수
- 테이블 - 변환 테이블은 maketrans 방법에 의해 번역 테이블에서 변환됩니다.
- deletechars - 필터링 할 문자열에있는 문자의 목록입니다.
반환 값
번역 된 문자열을 반환합니다.
예
다음의 예는 사용하는 () 함수를 변환을 보여줍니다
#!/usr/bin/python from string import maketrans # 引用 maketrans 函数。 intab = "aeiou" outtab = "12345" trantab = maketrans(intab, outtab) str = "this is string example....wow!!!"; print str.translate(trantab);
다음, 상기 출력 결과의 예 :
th3s 3s str3ng 2x1mpl2....w4w!!!
위의 예는 문자열 'X'와 'm'문자를 제거합니다 :
#!/usr/bin/python from string import maketrans # Required to call maketrans function. intab = "aeiou" outtab = "12345" trantab = maketrans(intab, outtab) str = "this is string example....wow!!!"; print str.translate(trantab, 'xm');
위의 출력의 예 :
th3s 3s str3ng 21pl2....w4w!!!