돌맹이
[Python] 문자열 포매팅(String Formatting) 본문
문자열 포매팅이란 문자열 안에 특정 값 또는 변수를 삽입하기 위한 방법이다.
문자열 포매팅 방식은 3가지다.
1. %기호 방식
2. format 메서드 방식
3. f 문자열 방식
예시)
month = 12, temperature = -5
print("12월 평균 온도는 -5도 입니다")
print("%d월 평균 온도는 %d도 입니다" %(month, temperature)) # %방식
print("{}월 평균 온도는 {}도 입니다".format(month, temperature)) # format 메서드 방식
print(f"{month}월 평균 온도는 {temperature}도 입니다") # f문자열 방식
'programming > Python' 카테고리의 다른 글
[Python] NumPy(넘파이) (0) | 2022.12.28 |
---|---|
[Python] Docstring(문서화) (0) | 2022.12.27 |
[Python] Dictionary 자료형 (0) | 2022.12.27 |
[Phython] Pythonic: 파이썬 문법 (0) | 2022.12.26 |