[Python] 시간 같은 두 자리 숫자 2자리로 고정시키기
2022. 8. 30. 09:32ㆍ파이썬
number = 1
print("%02d" % (number,))
Basically % is like printf or sprintf (see docs).
For Python 3.+, the same behavior can also be achieved with format:
number = 1
print("{:02d}".format(number))
For Python 3.6+ the same behavior can be achieved with f-strings:
number = 1
print(f"{number:02d}")
참조 : python - Display number with leading zeros - Stack Overflow
'파이썬' 카테고리의 다른 글
[python] list slicing (0) | 2022.09.05 |
---|---|
[Python] 현재 작업 경로 디렉토리 얻기 (0) | 2022.09.01 |
[Python] 데이터 프레임에 빈 행 앞(뒤)에 추가 (0) | 2022.08.21 |
[Python] Date Array 만들기 (0) | 2022.08.08 |
[Python] 시간 비교 (0) | 2022.07.04 |