format 문자열

유상민·2021년 7월 2일
0
txt = "      Strip white spaces.      "

print('[{}]'.format(txt))               # format 인자를 중괄호 내에 삽입


print('[{}]'.format(txt.strip()))		#- 양쪽 공백 제거 : strip()

인자는 인덱스나 키값처럼 지정 가능
A = '이름 : {name}, 나이 :{age}'.format(age=10, name:Tom)
이름 나이 자리에 format 한 값들이 들어감

format은 인자 자체를 삽입 할 수도 있고
함수로 처리된 값들을 삽입 할 수도 있다

0개의 댓글