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

■ str 클래스의 format 메소드에서 ! 기호를 사용하는 방법을 보여준다.

 

▶ 예제 코드 (PY)

dictionary1 = {"item" : "apple", "color" : "red"}

print("{item!s} is {color!s}".format(**dictionary1))

print("{item!r} is {color!r}".format(**dictionary1))

print("{item!a} is {color!a}".format(**dictionary1))

"""
apple is red
'apple' is 'red'
'apple' is 'red'
"""

※ !s, !r, !a는 각각 str 함수, repr 함수, ascii 함수를 실행한 결과와 동일하다고 보면 된다.

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

댓글을 달아 주세요