Python
rjust, ljust 함수
whiteglass
2021. 4. 6. 15:44
요약
문자열을 정렬할 때 사용하는 String에 속한 메소드
형식
- rjust( n , c=' ') : 문자열을 오른쪽으로 n만큼 정렬함. 빈칸은 c로 채워 넣는다.
- ljust( n , c=' ') : 문자열을 왼쪽으로 n만큼 정렬함. 빈칸은 c로 채워 넣는다.
예제
코드
a="abc"
print(a.rjust(10))
print(a.rjust(10,'#'))
b="def"
print(a.ljust(15))
print(a.ljust(15,'k'))
결과
abc
#######abc
abc
abckkkkkkkkkkkk
반응형