■ %를 사용해 문자열 포매팅 사용하기

----------------------------------------------------------------------------------------------------

print("I eat %d apples." % 3)

print("I eat %s apples." % "five")

print("I ate %d apples. so I was sick for %s days." % (10, "three"))

print("%10s" % "hi")

print("%-10sjane" % "hi")

print("%0.4f" % 3.42134234) # 소수점 4번째 자리까지 표시한다.

print("%10.4f" % 3.42134234)

 

[결과]


I eat 3 apples.

I eat five apples.

I ate 10 apples. so I was sick for three days.

        hi

hi        jane

3.4213

    3.4213

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG