1. c style의 %operator - 가장 느림

1
2
3
animal = "강아지"
text = "나는 %s가 좋아"%animal
print(text)
cs

 

2. str.format - 중간정도 속도

1
2
3
animal = "강아지"
text = "나는 {}가 좋아".format(animal)
print(text)
cs

 

3. f-string - 가장 빠름

1
2
3
animal = "강아지"
text = f"나는 {animal}가 좋아"
print(text)
cs

 

결론 쓰기도 편하고 가독성도 좋고 빠르기도 한 f-string을 쓰자

'컴퓨터 > 파이썬팁' 카테고리의 다른 글

python set vs list interation and in funciton speed test  (1) 2020.03.25
파이썬 set과 list의 특징  (0) 2020.03.17

+ Recent posts