print할 때 길이에 맞춰 오른쪽에 공백을 추가하고 싶습니다.
조회수 8157회
발생하는 문제 및 실행환경
앞에 0을 채우는 방법은
>>> print "'%06d'"%4
'000004'
이걸로 알고 있는데
'hi '
같이 뒤로 공백을 추가하려면 어떻게 해야될까요? str + " "*갯수
같이 쓸 수 있는건 알고 있습니다.
1 답변
-
str.ljust(width[, fillchar])를 쓰는 방법이 있습니다.
Return the string left justified in a string of length width. Padding is done using the specified fillchar (default is an ASCII space). The original string is returned if width is less than or equal to len(s).
왼쪽 정렬된 width길이의 스트링을 반환합니다. fillchar로 패딩 되며, fillchar의 기본값은 스페이스 한 칸입니다.
>>> 'hi'.ljust(10) 'hi '
댓글 입력