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  

+ Recent posts