반응형
Ruby 예 :
name = "Spongebob Squarepants"
puts "Who lives in a Pineapple under the sea? \n#{name}."
성공적인 파이썬 문자열 연결은 겉으로보기에 장황 해 보입니다.
해결 방법
name = "Spongebob Squarepants"
print(f"Who lives in a Pineapple under the sea? {name}.")
3.6 이전에 가장 가까운 것은
name = "Spongebob Squarepants"
print("Who lives in a Pineapple under the sea? %(name)s." % locals())
최신 Python 버전의 .format ()
메서드를 사용하는 동일한 코드는 다음과 같습니다.
name = "Spongebob Squarepants"
print("Who lives in a Pineapple under the sea? {name!s}.".format(**locals()))
tmpl = string.Template("Who lives in a Pineapple under the sea? $name.")
print(tmpl.substitute(name="Spongebob Squarepants"))
참조 페이지 https://stackoverflow.com/questions/4450592
반응형
'파이썬' 카테고리의 다른 글
파이썬에서 데이터를 쉽게 저장 /로드 (0) | 2020.10.18 |
---|---|
파이썬 for 루프에서 목록 목록을 만들고 채우는 방법 (0) | 2020.10.18 |
파이썬 matplotlib : 기능 이름으로 기능 중요성 플롯 (0) | 2020.10.18 |
파이썬 'Conda'는 내부 또는 외부 명령으로 인식되지 않습니다. (0) | 2020.10.18 |
파이썬 로 시작하는 파이썬 목록 항목을 찾는 방법 (0) | 2020.10.18 |
댓글