format2 string unpacking - 문자열 언팩킹 언팩킹이란? 요소를 여러 변수에 나누어 담는 것 locals()? 현재 scope 에 있는 local 변수를 딕셔너리 type( {key:value} ) 으로 반환 >>> nums = [1,2,3,4] # unpacking >>> a,*b = nums >>> a 1 >>> b [2,3,4] >>> f'{a} {b} {nums}' 1 [2,3,4] [1,2,3,4] # unpacking >>> '{a} {b} {nums}'.format(**locals()) 1 [2,3,4] [1,2,3,4] 2020. 8. 23. 숫자 출력 시 width에 맞춰서 앞에 0 채우기 앞에 0을 채워서 스트링 길이를 width에 맞추기 >>> '3'.zfill(5) >>> '%05d'% 3 >>> format(3,'05') >>> '{0:05d}'.format(3) >>> '{n:05d}'.format(n=3) >>> '3'.rjust(5,'0') '00003' 2020. 7. 28. 이전 1 다음