문자열 포맷팅

Changyeol Choi·2021년 2월 7일

Python

목록 보기
4/4

% 연산자, format,f-string 중에서 f-string이 가장 빠르다.

>>> import timeit
>>> timeit.timeit("""name = "Eric"
... age = 74
... '%s is %s.' % (name, age)""", number = 10000)
0.004672400000004018
>>> timeit.timeit("""name = "Eric"
... age = 74
... '{} is {}.'.format(name, age)""", number = 10000)
0.005111699999929442
>>> timeit.timeit("""name = "Eric"
... age = 74
... f'{name} is {age}.'""", number = 10000)
0.0034804000000576707
profile
10년 후...내 모습을 위한 첫걸음

0개의 댓글