파이썬 f문자열

1 개요[ | ]

f-string Formatting in Python
파이썬 f-문자열 포맷팅, f문자열, f스트링
  • 파이썬 3.6부터 지원하는 문자열 포맷팅 형식
  • 자료형에 관계없이 사용할 수 있어 편리하다.
apples = 4
print(f"I have {apples} apples")
apples = 4
print(f'I have {apples} apples')
fruits = ['apple', 'banana', 'orange']
print(f'I have {fruits}')
name = "Fred"
print( f"He said his name is {name}." )
name = "John"
age = 5
print(f"My name is {name} and I am {age} years old. Please call me {name}.")
중첩 필드(nested fields)
import decimal
width = 10
precision = 4
value = decimal.Decimal("12.34567")
print( f"result: {value:{width}.{precision}}" )

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}