print() 사용법을 알아 보겠습니다.
더 많은 내용은 아래 링크에서 확인할 수 있습니다.
(https://www.python-course.eu/python3_formatted_output.php)
# 기본 출력
파이썬에서 문자열을 만드는 방법은 아래와 같이 총 4가지가 있습니다.
print('python start') #작은 따옴표로 둘러싸기
print("python start") #큰 따옴표로 둘러싸기
print("""python start""") #큰 따옴표 3개를 연속으로 써서 둘러싸기
print('''python start''') #작은 따옴표 3개를 연속으로 써서 둘러싸기
===실행 결과===
python start
python start
python start
python start
# 문자열에 작은 따옴표 넣기
a = "Welcome to 'python' world"
print(a)
=== 실행 결과 ===
Welcome to 'python' world
# 문자열에 큰 따옴표 넣기
say = '"welcome to python world!" he says'
print(say)
=== 실행 결과 ===
"welcome to python world!" he says
# 백슬러시 사용하기
a = "Welcome to \"python\" world"
say = '\'welcome to python world!\' he says'
print(a)
print(say)
=== 실행 결과 ===
Welcome to "python" world
'welcome to python world!' he says
# end 옵션으로 문장 이어주기
print('Welcome', end=' ')
print('to', end=' ')
print('python', end=' ')
=== 실행 결과 ===
Welcome to python
# format 사용하기
print('{} {}'.format('one', 'two'))
print('{1} {0}'.format('one', 'two'))
print('{:>10}'.format('nice')) #총 10자리 출력 - 왼쪽부터 공백
print('{:*<10}'.format('nice')) #총 10자리 출력 - 오른쪽 공백
print('{:^10}'.format('nice')) #중앙정렬
print('{:10.5}'.format('nicepython')) #10자리를 확보하는데 5개만 나와라
=== 실행 결과 ===
one two
two one
nice
nice******
nice
nicep
'Language > Python' 카테고리의 다른 글
06. python 자료형 - 숫자형 (0) | 2019.12.07 |
---|---|
05. python - 비교 연산자 & 논리 연산자 (0) | 2019.11.16 |
04. python 지원 자료형 (0) | 2019.09.19 |
02. Python 환경변수 설정하기 (0) | 2019.09.19 |
01. Windows에서 Python 설치하기 (0) | 2019.09.19 |