공부합시다!/python
2. 출력: print
간서치
2023. 1. 10. 00:12
728x90
오늘은 python 출력을 학습합니다.
어째든 간에 프로그래밍을 해서 어떤 결과값을 얻었다면 표준 출력이든 파일로든 출력이 되어야 합니다.
해서 맨처음 배우는 부분이기도 하지요!
근데 대부분 여기서 땡 하고 맙니다!
이번에는 조금 진중하게 접근해 보세요!
# 기본 출력
print('Hello Python!')
print("Hello Python!")
print('''Hello Python!''')
print("""Hello Python!""")
print("'Hello' Python!")
print('"Hello" Python!')
print()
# Separator
print('T','E','S','T')
print('T','E','S','T', sep='')
print('2022','11','11')
print('2022','11','11', sep='-')
print('ksd7248','naver.com', sep='@')
# end 옵션 사용
print('Welcome To', end='')
print('the Python World!', end='')
print('and Hello World')
print('Welcome To', end=' ')
print('the Python World!', end=' ')
print('and Hello World')
# format 옵션 사용
# 대괄호 [], 중괄호 {}, 소괄호 ()
print('{} and {}'.format('you','me'))
print('{0} and {1} and {0}'.format('you','me'))
print('{b} and {a}'.format(b="you", a='me'))
# %s : 문자, %d : 정수, %f : 실수
#print("%s's favorite Number is %d" % (8,'Sungdae'))
print("%s's favorite Number is %d" %('Sungdae', 8))
print('Test1:%5d, Price:%4.2f' %(832, 777.6789))
print('Test1:{0:5d}, Price:{1:4.2f}'.format(832,777.6789))
print('Test1:{a:5d}, Price:{b:4.2f}'.format(a=832,b=777.6789))
# escape 코드
"""
'''
\n : 개행
\t : Tab
\\ : 문자
\' : 문자
\" : 문자
\r : 캐리지 리턴
\f : 폼 피드
\a : 벨소리
\b : 백스페이스
\000 : Null 문자
'''
"""
print("'sdkim'")
print("""'sdkim'""")
print('"sdkim"')
print('''"sdkim"''')
print("\"sdkim\"")
print('\t\t\tsdkim\n\n')
print('sdkim')
그 외 추가적인 것들은 그때 그때 또 설명하도록 하겠습니다.
728x90