[python] 출력 방법 알아보기

값 여러개 출력하기

print(값1, 값2, 값3) 각 값들이 공백으로 분리되어 출력된다.

print('Hello', 'python')  # Hello python

sep으로 값들이 무엇으로 분리되어 출력될지 정할 수 있다.
print(값1, 값2, sep=’문자 또는 문자열’)

print(1, 2, 3, sep='abcd')  # 1abcd2abcd3

줄바꿈 활용하기

sep으로 각 줄에 개행 넣기

print(1, 2, 3, sep='\n')
# 1
# 2
# 3

print는 기본적으로 출력 값 끝에 \n을 붙이는데, 이를 end를 이용해서 다른 것으로 바꿀 수 있다.
print(값, end=’문자 또는 문자열’)

print(1, end=' ')
print(2, end=' ')
print(3)  # 1 2 3

print(1, 2, 3, sep=', ', end=' ')
print('done!')  # 1, 2, 3 done!

Updated:

Leave a comment