본문 바로가기
파이썬

파이썬에서 n 개의 문자로 채우는 방법

by º기록 2020. 10. 27.
반응형

나는 a를 취하는 pad_with_n_chars (s, n, c) 함수를 정의해야한다. string 's', an integer 'n', and a character 'c' and returns a string consisting of 's' padded with 'c' to create a string with a centered 's' of length 'n'. For example, pad_with_n_chars(”dog”, 5, ”x”) should return the 문자열 " xdogx ".

 

해결 방법

 


In [18]: '{s:{c}^{n}}'.format(s='dog',n=5,c='x')
Out[18]: 'xdogx'

 

참조 페이지 https://stackoverflow.com/questions/4008546

 

 

반응형

댓글