format

· Python
- % 이용 >>> '%d'%1 '1' >>> '%3d'%1 ' 1' >>> '%03d'%1 '001' '%d'%숫자 %d 자리에 숫자 포매팅 '%자리수d'%숫자 자리수대로 앞에 빈 칸을 채운 후 숫자로 포매팅 '%0자리수d'%숫자 자리수대로 앞에 0을 채운 후 숫자로 포매팅 - format 이용 >>> '{0:3d}'.format(1) ' 1' >>> '{0:03d}'.format(1) '001' '{0:자리수d}'.format(숫자) '{0:0자리수d}'.format(숫자) >>> '{0:3}'.format(1) ' 1' >>> '{0:03}'.format(1) '001' d를 빼고 입력시에도 실행됩니다.
· Python
format을 이용해 문자열에서 원하는 부분에 특정 변수의 값을 넣을 수 있습니다. >>> 'Welcome, {}.'.format('hello01') 'Welcome, hello01.' >>> 'Welcome, {1}.'.format(100, 'hello01') 'Welcome, hello01.' >>> 'Welcome, {} {} {}.'.format('hello01', 'hello02', 'hello03') 'Welcome, hello01 hello02 hello03.' >>> '{}'.format(값) >>> '{인덱스}'.format(값) 값이 여러개일 때 인덱스를 표시해주면 그 인덱스의 값이 출력됩니다. >>> 값이 여러개일 때 { }안 아무것도 표시하지 않으면 차례대로 값이 출력됩니다. >>>..
rimchoi
'format' 태그의 글 목록