Python

[Python] print 함수

건뱅 2019. 4. 22.
반응형

본 강의는 Visual Studio Code 를 이용하여 강의를 진행한다. 

배운 내용 코드를 올리고 정리하면서 블로그에 남길 생각이다.

 

Print 함수

  print 함수는 파이썬에서 가장 기본적인 Output(출력) 함수이다.

- 기본 출력

- Separator, End 옵션

- Format 형식 출력

- Escape Code 사용법

 

 

<코드>

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Section02-1
# 파이썬 기초 코딩
# Print 구문의 이해
 
# 기본출력
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('2019''02''19', sep='_')
print('niceman''google.com', sep='@')
 
# end 옵션 사용
print('Welcome To', end='')
print(' the black parade', end='')
print(' piano notes')
 
print() #줄바꿈
# format 사용 [], {}, ()
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" %('Keonho',7)) 
 
print("Test1: %5d, Price: %4.2f" %(7766534.123))
# %5d : 5자리의 숫자가 온다고 자릿수를 지정, %4.2f: 정수부분은 4자리 소수부분은 2자리 인 실수
print("Test1: {0: 5d}, Price: {1: 4.2f}".format(7766534.123))
print("Test1: {a: 5d}, Price: {b: 4.2f}".format(a=776, b=6534.123))
 
 
"""
참고 : Escape 코드 => 탈출문자
\ (역슬래쉬)다음 문자는 그대로 표시
 
\n : 개행
\t : 탭
\\ : 문자
\' : 문자
\" : 문자
\r : 캐리지 리턴
\f : 폼 피드
\a : 벨 소리
\b : 백 스페이스
\000 : 널 문자
 
"""
 
print("'you'")
print('\'you\'')
print('"you"')
print("""'you'""")
print('\\you\\\n')
print("\t\t\ttest")
# tab 1번에 spacebar 4번
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
 

 

<결과화면>

 

* 주석 : #태그로 가능하며, '#' 다음 공백을 띄우는게 암묵적인 규칙

 

반응형

'Python' 카테고리의 다른 글

[Phython] 파이썬을 시작하며..  (4) 2019.04.21

댓글