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
반응형
그리드형(광고전용)
'Python > Common' 카테고리의 다른 글
[PYTHON/COMMON] str 클래스 : format 메소드에서 b d x o c 기호 사용하기 (0) | 2022.08.24 |
---|---|
[PYTHON/COMMON] str 클래스 : format 메소드에서 + - 기호 사용하기 (0) | 2022.08.24 |
[PYTHON/COMMON] str 클래스 : format 메소드에서 < > ^ = 기호 사용하기 (0) | 2022.08.24 |
[PYTHON/COMMON] str 클래스 : format 메소드에서 locals 함수 사용시 ** 기호 사용하기 (0) | 2022.08.24 |
[PYTHON/COMMON] repr 함수 : ascii 함수 비교하기 (0) | 2022.08.24 |
[PYTHON/COMMON] str 클래스 : format 메소드에서 locals 함수 사용시 ** 기호 사용하기 (0) | 2022.08.24 |
[PYTHON/COMMON] str 클래스 : format 메소드에서 dict 객체로 문자열 포맷시 ** 기호 사용하기 (0) | 2022.08.24 |
[PYTHON/COMMON] str 클래스 : format 메소드에서 locals 함수 사용하기 (0) | 2022.08.24 |
[PYTHON/COMMON] str 클래스 : format 메소드를 사용해 dict 객체로 문자열 포맷하기 (0) | 2022.08.24 |
[PYTHON/COMMON] str 클래스 : zfill 메소드를 사용해 빈칸 대신 0 채우기 (0) | 2022.08.23 |
댓글을 달아 주세요