첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

■ str 클래스의 maketrans 메소드를 사용해 translate 메소드에서 사용할 번역용 맵을 구하는 방법을 보여준다.

 

▶ 예제 코드 (PY)

dictionary1 = str.maketrans({"p" : "P"})

print("python is powerful".translate(dictionary1))

"""
Python is Powerful
"""

dictionary2 = str.maketrans("poieu", "P0129")

print("python is powerful".translate(dictionary2))

"""
Pyth0n 1s P0w2rf9l
"""

dictionary3 = str.maketrans("p", "P", "!")

print("python is powerful!!!!!".translate(dictionary3))

"""
Python is Powerful
"""
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요