Python 2. Print함수

min seung moon·2021년 8월 10일
0

PythonBasic

목록 보기
2/7

1. Print

  • 가장 기본적인 Output 함수
  • 기본 출력
  • Separator, End 옵션 사용
  • Format 형식 출력
  • Esacape Code 사용법

2. Print 실습

01. 기본출력('' , "")

  • 따옴표의 갯수는 상관이 없고 짝을 잘 맞추어 주면 된다

# 기본출력('' , "")
print('Hello Python!')
print("Hello Python!")
# 따옴표의 갯수는 상관이 없고 짝을 잘 맞추어 주면 된다
print('''Hello Python!''')
print("""Hello Python!""")

02. Separator 옵션 사용

print('T', 'E', 'S', 'T', sep='')
print('2019', '02', '19', sep='-')
print('niceman', 'google.com', sep='@')

03. End 옵션 사용

  • end로 개행을 지워서 다음 라인과 연결 시켜준다
print('Welcom To ', end='')
print(' the black parade ', end='')
print(' piano notes')

04. Format 사용({})

  • %s : 문자, %d : 정수, %f

print('{} and {}'.format('You', 'Me'))
print('{0} and {1} and {0}'.format('You', 'Me'))
print('{a} are {b}'.format(a='You', b='Me'))

# %s : 문자, %d : 정수, %f
print("%s's favorite number is %d" % ('He', 7))

print("Test1 : %5d, Price : %4.2f" % (776, 6543.123))
print("Test1 : {0: 5d}, Price : {1: 4.2f}".format(776, 6543.123))
print("Test1 : {a: 5d}, Price : {b: 4.2f}".format(a=776, b=6543.123))

05. Escape

  • \n : 개행
  • \t : 탭
  • \ : 문자
  • \' : 문자
  • \" : 문자
  • \r : 캐리지 리턴
  • \f : 폼 피드
  • \a : 벨 소리
  • \b : 백 스페이스
  • \000 : 널 문자
print("'You'")
print('\'You\'')
print('"You"')
print("\"You\"")
print("You\n\n\n")
print('\t\t\tYou')

profile
아직까지는 코린이!

0개의 댓글