파이썬 format을 이용해 초간단하게 1000의 단위마다 콤마 붙이기 (Putting comma every 3 digit in python)
숫자를 보기 좋게 만들기 위해서 천의 단위마다 콤마찍는 것이 좋다. 파이썬 스트링 format 메소드를 사용해 아주 간단하게 이게 가능하다.
Putting comma every 3 digit in a number can be done very easily by python's string format method. This is not only for leaving a record for myself in the future and sharing with those who do not know this)
print("{:,}".format(234234234234))
을 실행해보면,
On execution of the code above
'234,234,234,234'
이렇게 나온다. 물론 반환되는 값은 콤마를 포함하는 string이다. 따라서 계산이 다 끝난 최종값을 넣어주는 것이 좋겠다.
(you get that. Of course it returns a string. Thus, you better use this after every calculation has been done. )
이상
(End)
'Regular Python' 카테고리의 다른 글
secrets 모듈을 사용해 리스트에서 무작위 item 추출하는 방법 (Extracting a random member from a list) (0) | 2017.12.02 |
---|---|
ast module for converting a List-type-string into a real python list (0) | 2017.05.07 |