기존 python에서는 string에 변수를 넣기 위해서는 C와 유사한 아래와 같은 형식이나,
str = "Hello, World, My name is %s, I'm %d years old" % (name, age)
format()을 사용하여 변수를 매핑하여 사용하였다.
str = "Hello, World, My name is {}, I'm {} years old".format(name, age)
Python 3.6부터 f-string을 지원하여 이를 사용 가능하다.
str = f"Hello, World, My name is {name}, I'm {age} years old"
반응형
반응형
'IT > Python' 카테고리의 다른 글
[Python] json의 key, value에 따른 데이터 추출 (0) | 2023.03.10 |
---|---|
[Python] Requests timeout 설정 (0) | 2023.01.27 |
[Python] 2차원 배열 정렬 방법 (0) | 2022.07.31 |
[Python] "return list.sort()"는 None 일 때 (0) | 2022.07.31 |
댓글