[Python] f-string 소수점 자릿수 표기 방법

2020. 7. 30. 13:48Python

f-string에서 소수점 자릿수를 지정하여 출력할 수 있다.

print(f'소수점 자릿수 표기하기:: { 변수이름: .[소수점자릿수]f }')

예시

name = "준서"
scores = [95, 100 , 90]
print(f"{name} 님의 평균 점수는 {round(sum(scores)/float(len(scores))):.2f} 입니다.")