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