-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormat.py
More file actions
30 lines (23 loc) · 1.07 KB
/
Copy pathFormat.py
File metadata and controls
30 lines (23 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 빈 자리는 빈공간으로 두고, 오른쪽 정렬을 하되, 총 10자리 공간을 확보
print("{0: >10}".format(500)) # 0과 10사이에 빙공간으로 두고 '>' 오른쪽 정렬하면서 500을 출력한다.
'''
# 출력물
500 # 총 10칸 확보, 오른쪽 정렬, 500 출력.
'''
# 양수일 땐, +로 표시, 음수일 땐, -로 표시
print("{0: >+10}".format(500))
print("{0: >-10}".format(-500))
# 왼쪽으로 정렬하고, 빈칸으로는 _로 채움
print("{0:_<+10}".format(500))
# 3자리 마다 콤마를 찍어주기
print("{0:,}".format(100000000000)) # 자동으로 3자리마다 , 출력.
# 3자리 마다 콤마를 찍어주기 출력 (+-도 붙이기)
print("{0:+,}".format(100000000000))
print("{0:-,}".format(-100000000000))
# 3자리 마다 콤마를 찍고 부호도 붙이고 자릿수 확보하기
# 빈자리는 ^로 표기
print("{0:^<+30,}".format(100000000000)) # 빈칸에 ^ 총 30자리 확보하고 3칸마자 , 표시
# 소수점 출력
print("{0:f}".format(5/3))
# 소수점 2번째자리까지 출력
print("{0:.2f}".format(5/3))