반응형
질문
나는 다음과 같은 코드를 가지고 있습니다.
test = "have it break."
selectiveEscape = "Print percent % in sentence and not %s" % test
print(selectiveEscape)
원하는 출력 결과는 다음과 같습니다:
Print percent % in sentence and not have it break.
실제로 발생한 일은 다음과 같습니다:
selectiveEscape = "Use percent % in sentence and not %s" % test
TypeError: %d format: a number is required, not str
답변
>>> test = "have it break."
>>> selectiveEscape = "Print percent %% in sentence and not %s" % test
>>> print selectiveEscape
Print percent % in sentence and not have it break.
반응형
댓글