사용자 도구

사이트 도구


wiki:ai:python:print_함수의_이해

print함수의 이해

  • description : python에서의 print 함수 이해
  • author : 도봉산핵주먹
  • email : hylee@repia.com
  • lastupdate : 2020-06-17

print함수의 이해

예제 코드

# Section02-1
# 파이썬 기초 코딩
# Print 구문의 이해
# 참조 : https://www.python-course.eu/python3_formatted_output.php
 
"""
참고 : Escape 코드
 
\n : 개행
\t : 탭
\\ : 문자
\' : 문자
\" : 문자
\r : 캐리지 리턴
\f : 폼 피드
\a : 벨 소리
\b : 백 스페이스
\000 : 널 문자
...
 
"""
# 기본 출력
print("=== 기본 출력 ===")
print('Hello Python!')  # 문법적 중요
print("Hello Python!")  # 텍스트 의미
print("""Hello Python!""")
print('''Hello Python!''')
 
print()
 
# separator 옵션 사용
print("=== separator 옵션 ===")
print('T', 'E', 'S', 'T', sep='')
print('2019', '02', '19', sep='-')
print('niceman', 'google.com', sep='@')
 
print()
 
# end 옵션 사용
print("=== end 옵션 ===")
print('Welcome To', end=' ')
print('the black parade', end=' ')
print('piano notes')
 
print()
 
# file 옵션 사용
import sys
 
print("=== file 옵션 ===")
print('GeeksForGeeks', file=sys.stdout)
 
print()
 
print("%s's favorite number is %d" % ('hylee', int(6)))
 
# format 사용
print("=== format 사용 ===")
print('{} and {}'.format('You', 'Me'))
print('{0} and {1} and {0}'.format('You', 'Me'))
print('{var1} are {var2}'.format(var1='You', var2='Niceman'))
 
print()
 
print(r"=== %d, %f, %s 사용 ===")
# %d, %f, %s
print("Test1: %d, Price: %.2f" % (776, 6534.123))
print("Test2: {0:2d}, Price:{1:4.2f}".format(776, 6534.123))
print("Test3: {a: d}, Price:{b: 2.1f}".format(a=776, b=6534.123))

실행 콘솔

=== 기본 출력 ===
Hello Python!
Hello Python!
Hello Python!
Hello Python!
 
=== separator 옵션 ===
TEST
2019-02-19
hylee@google.com
 
=== end 옵션 ===
Welcome To the black parade piano notes
 
=== file 옵션 ===
GeeksForGeeks
 
hylee's favorite number is 6
=== format 사용 ===
You and Me
You and Me and You
You are Niceman
 
=== %d, %f, %s 사용 ===
Test1: 776, Price: 6534.12
Test2: 776, Price:6534.12
Test3:  776, Price: 6534.1

Tip

/var/services/web/dokuwiki/data/pages/wiki/ai/python/print_함수의_이해.txt · 마지막으로 수정됨: 2023/01/13 18:44 (바깥 편집)