까먹으면 적어두자

rjust, ljust 함수 본문

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

 

반응형

'Python' 카테고리의 다른 글

파이썬 여러버전 설치하기  (0) 2021.07.09
bin 함수  (0) 2021.04.06
Python에서 자리수 맞추기  (0) 2021.04.06
Comments