강의

멘토링

커뮤니티

Inflearn Community Q&A

bravoyou's profile image
bravoyou

asked

Getting Started with Programming: Introduction to Python (Inflearn Original)

How to use Python Print (1-3)

float를 이용한 문법 질문드립니다.

Written on

·

298

0

print("art: %5d, price: %08.2f" % (453, 59.058))

위와 같은 코드를 작성했을때의 출력물과, float를 이용해서 작성했을때의 출력물과 같게 만들기 위해

print('{art: 5d}{price: 08.2d}'.format(453, 59.058))

위와 같은 코드를 작성해보았는데요, 출력이 안됩니다.

 

어떤 잘못을 한걸까요?

 

python

Answer 1

0

bravoyou님의 프로필 이미지
bravoyou
Questioner

소수부분을 위해 d > f 로 수정했습니다.

print('{art: 5d}{price: 08.2f}'.format(453, 59.058))

niceman님의 프로필 이미지
niceman
Instructor

앞자리만 보여드릴께요 출력해보세요.

format함수 사용법이 틀렸네요!

print("art:", '{0:5d}'.format(453))

bravoyou's profile image
bravoyou

asked

Ask a question