파이썬 문자열 rjust() 메서드
예시
"banana"라는 단어의 20자 길이의 오른쪽 정렬 버전을 반환합니다.
txt = "banana"
x = txt.rjust(20)
print(x, "is my
favorite fruit.")
참고: 결과에서 실제로는 단어 banana의 왼쪽에 14개의 공백이 있습니다.
정의 및 사용
이 rjust()
메서드는 지정된 문자(기본값은 공백)를 채우기 문자로 사용하여 문자열을 오른쪽 정렬합니다.
통사론
string.rjust(length, character)
매개변수 값
Parameter | Description |
---|---|
length | Required. The length of the returned string |
character | Optional. A character to fill the missing space (to the left of the string). Default is " " (space). |
더 많은 예
예시
문자 "O"를 패딩 문자로 사용:
txt = "banana"
x = txt.rjust(20, "O")
print(x)