[python] center, rjust, ljust, zfill 함수

901 단어 pythonpython
  1. center(width, [fillchar]) 가운데 정렬
print("a".center(3,"*")) # *a*
print("123".center(9,"a")) # aaa123aaa

# 공백은 width만 넣어도 됨.
print("coding".center(10," ")) #   coding
print("coding".center(10)) #   coding
  1. rjust(width, [fillchar]) 오른쪽정렬
# rjust
print("a".rjust(3,"*")) # **a
print("123".rjust(9,"a")) # aaaaaa123
print("coding".rjust(10)) #    coding
  1. ljust(width, [fillchar]) 왼쪽 정렬
print("a".ljust(3,"*")) # a**
print("123".ljust(9,"a")) # 123aaaaaa
print("coding".ljust(10)) # coding
  1. zfill(width) 공백부분에 0 채우기
print("a".zfill(3)) # 00a
print("123".zfill(9)) # 000000123
print("coding".zfill(10)) # 0000coding

좋은 웹페이지 즐겨찾기