-
zfill string 자릿수 맞추기python 기초 2024. 2. 26. 19:07728x90
숫자를 string변환할 때, 자릿수에 맞춰 앞에 0이 붙어있는 경우들이 있다.
이를 코드로 구현할 때 쓰는 함수가 zfill이다.
위와 같이 사용한다. for n in range(10): print(str(n).zfill(2))
위의 예제를 돌리면 아래의 결과가 나온다.
00 01 02 03 04 05 06 07 08 09
728x90'python 기초' 카테고리의 다른 글
pandas read_csv sep 옵션 (0) 2024.08.25 pandas dadtaframe 수치형 / 범주형 분리 (0) 2024.08.24 numpy array slicing이 원본 크기를 넘어 섰을 때 (0) 2024.01.01 pillow-simd install 에러 (0) 2023.12.18 python mkdir makedirs exist_ok (0) 2023.11.14