Python

Python print 방식

오렌지마끼야또 2022. 6. 13. 14:15
728x90
반응형

 

 

 

print(f' ') 방식은 파이썬 3.6부터 지원하는 기능

 

 

print(f'2의 10제곱 : {2**10}')

-> 2의 10제곱 : 1024

 

 

print(f'he says \n"Python\'s power is awesome"')

he says 
"Python's power is awesome"

 

 

print(f'3회 반복 : {", ".join(["Python"] * 3)}')

-> 3회 반복 : Python, Python, Python

 

 

print('''1번째 줄
2번째 줄
3번째 줄''')

1번째 줄
2번째 줄
3번째 줄

 

 

print('우측 정렬 + 소수점 둘째까지 %%10.2f  |%10.2f|' %(3.141592))
print('좌측 정렬 + 소수점 둘째까지 %%-10.2f |%-10.2f|' %(3.141592))

우측 정렬 + 소수점 둘째까지 %10.2f  |      3.14|
좌측 정렬 + 소수점 둘째까지 %-10.2f |3.14      |

 

 

print('좌측 정렬 |{0:<10}|'.format('hi'))
print('우측 정렬 |{0:>10}|'.format('hi'))
print('중앙 정렬 |{0:^10}|'.format('hi'))

좌측 정렬 |hi        |
우측 정렬 |        hi|
중앙 정렬 |    hi    |

 

 

print('중앙 정렬 + 나머지 !로 채우기 |{0:!^10}|'.format('hi'))

중앙 정렬 + 나머지 !로 채우기 |!!!!hi!!!!|

 

 

728x90
반응형