본문 바로가기

[+] Information/[-] Reference

[Python Reference] maketrans () 메서드

Python String maketrans() Method

설명 : Description:

이 메소드는 번역 테이블을 반환 outtab 문자열에서 같은 위치에있는 문자에 intab 문자열지도에서 각 문자를. This method returns a translation table that maps each character in the intab string into the character at the same position in the outtab string. 그런 다음이 테이블 함수는 () 번역에 전달됩니다. Then this table is passed to the translate() function. intab과 outtab 모두 같은 길이를 가지고 있어야합니다. Note that both intab and outtab must have the same length.

구문 : Syntax:

str.maketrans (intab, outtab]); str.maketrans(intab, outtab]);

매개 변수 : Parameters:

여기에 매개 변수의 세부 사항은 다음과 같습니다 : Here is the detail of parameters:

  • intab : 실제 문자를 가지고 문자열입니다. intab : string having actual characters.

  • outtab : 해당 매핑 문자를 가지고 문자열입니다. outtab : string having corresponding mapping character.

값을 반환합니다 : Return Value:

그것은 사용하는 변환 테이블 번역 () 함수를 반환합니다. It returns a translate table to be used translate() function.

예 : Example:

이 예제는 문자열의 모든 모음은 그 모음의 위치로 대체됩니다 : This example every vowel in a string is replaced by its vowel position:

#!는 / usr / 빈 / 파이썬 #!/usr/bin/python

문자열을 가져옵니다 maketrans에서 # maketrans 함수를 호출하기 위해 필요합니다. from string import maketrans # Required to call maketrans function.

intab = "aeiou" intab = "aeiou"
outtab = "12345" outtab = "12345"
trantab = maketrans (intab, outtab) trantab = maketrans(intab, outtab)

하위 버전과의 호환 = "이것은 문자열 예입니다 .... 와우 !!!"; str = "this is string example....wow!!!";
인쇄 str.translate (trantab); print str.translate(trantab);

이것은 다음과 같은 결과를 생산합니다 This will produce following result:

2x1mpl2을 str3ng th3s 3S로 .... w4w! th3s 3s str3ng 2x1mpl2....w4w!!!

'[+] Information > [-] Reference' 카테고리의 다른 글

[Python Reference] ftplib  (0) 2011.12.15
[Python Reference] re 모듈  (0) 2011.10.23
[Win32 Reference] CreateWindowA() API  (0) 2011.10.08
[Win32 Reference] MessageBoxA() API  (0) 2011.10.08