python 문자열 format (ongoing)

써니·2020년 12월 8일
0

Python

목록 보기
2/9
post-thumbnail

String formatting?
: 문자열 중간 중간에 특정 변수의 값 대입 가능하게 함

  1. % 와 서식기호
  2. format 함수 ('~~{}'.format())
    :'{인덱스0}, {인덱스1}'.format(값0, 값1)

EX1: print('{0} x {1}={2}').format(a,b,a*b))
EX2: print('{a} , {b}').format(a=1,b=2))

-문자열 정렬하기
-왼쪽 정렬: <
-오른쪽 정렬: >
s9 = 'this is {0:<10} | done {1:<5} |'.format('left', 'a')
s10 = 'this is {0:>10} | done {1:>5} |'.format('right', 'b')
s11 = 'this is {0:^10} | done {1:^5} |'.format('center', 'c')

  1. f-string

(참고:
https://blockdmask.tistory.com/424)

0개의 댓글