[요약]파이썬(Python) Print함수의 이해
# print함수 및 구문의 각종 사용 사례를 살펴봅니다. # 기본출력 print('Hello Python!') # > Hello Python! print("Hello Python!") # > Hello Python! print("""Hello Python!""") # > Hello Python! print('''Hello Python!''') # > Hello Python! # 줄넘김효과 print() # Separator 옵션 사용 print('T', 'E', 'S', 'T') # > T E S T print('T', 'E', 'S', 'T', sep='') # > TEST print('2019', '02', '25', sep='-') # > TEST print('goodman', 'gmail.com', sep='@') # > goodman@gmail.com # end 옵션 사용 - 줄넘김 대신에 end=에 지정된 문자가 표시됨 print('Welcome To', end=' ') # > Welcome To //다음줄과 ' '로 이어서 나옴 print('the black parade', end='') # the black parade, //다음줄과 붙어 버림 print('piano notes') # piano notes # format 사용, 중괄호{} 사용 print('{} and {}'.format('You', 'Me')) # > You and Me print("{0} and {1} and {0}".format('You', 'Me')) # > You and Me and You print("{a} are {b}.".format(a='You', b='goodman')) # > You are goodman # format의 형식 문자 사용하기, %s:문자, %d:숫자, %f:실수 print("%s's favorite number is %d" %('Jack', 10)) # > Jack's favorite number is 10 print("Test1: %5d, Price: %4.2f" %(776, 6534.123)) # > Test1: 776, Price: 6534.12 print("Test1: {0: 5d}, Price:{1: 4.2f}".format(776, 6534.123)) # > Test1: 776, Price: 6534.12 print("Test1: {a: 5d}, Price:{b: 4.2f}".format(a=776, b=6534.123)) # > Test1: 776, Price: 6534.12 # Escape Code 사용 # \n : 개행 # \t : 탭 # \\ : \ 문자 # \' : '문자 # \r : 캐리지리턴 # \f : 폼피드 # \a : 벨소리 # \b : 백스페이스 # \000 : 널문자 # ... print("'you'") # > 'you' print('\'you\'') # > 'you' print('"you"') # > 'you' print('\'you\'') # > 'you' print("""'you'""") # > 'you' print('\\you\\\n\n') # > '\you\줄바뀜두번' print('\tyou\tTest') # > you Test
'프로그래밍 > Python' 카테고리의 다른 글
[요약]파이썬(Python) 문자형 처리 (0) | 2020.09.01 |
---|---|
[요약]파이썬(Python) 가상환경 설정 및 패키지 설치 (0) | 2020.08.31 |
[요약]파이썬(Python) 코딩 둘러보기 (0) | 2020.08.31 |
[요약] 파이썬(Python) 개발환경 설정 - Windows (0) | 2020.08.31 |
Python 라이브러리 정리 (0) | 2018.01.01 |