-
Notifications
You must be signed in to change notification settings - Fork 0
/
python_st_05.html
504 lines (501 loc) · 23.4 KB
/
python_st_05.html
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
<!DOCTYPE html>
<html lang="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
.utterances {
position: relative;
box-sizing: border-box;
width: 100%;
max-width: 760px;
margin-left: auto;
margin-right: auto;
}
.utterances-frame {
color-scheme: light;
position: absolute;
left: 0;
right: 0;
width: 1px;
min-width: 100%;
max-width: 100%;
height: 100%;
border: 0;
}
</style>
<title>Python 입문</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<script src="https://kit.fontawesome.com/77ad8525ff.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://bluecow03.github.io/pythonst/python/style.css">
<link rel="stylesheet" href="https://bluecow03.github.io/pythonst/python/collapsible-chapters.css">
<link rel="stylesheet" href="https://bluecow03.github.io/pythonst/python/website.css">
<link rel="stylesheet" href="https://bluecow03.github.io/pythonst/python/search.css">
<link rel="stylesheet" href="https://bluecow03.github.io/pythonst/python/website(1).css">
<meta name="HandheldFriendly" content="true">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="./python/python.png">
<link rel="shortcut icon" href="./python/python.ico" type="image/x-icon">
<link rel="next" href="https://bluecow03.github.io/pythonst/python/python_st_00.html">
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li class="chapter active expanded" data-level="1.1" data-path="./">
<a href="https://bluecow03.github.io/pythonst/python_main.html">
Python
</a>
</li>
<li class="chapter expanded" data-level="1.2" data-path="basics/">
<a href="https://bluecow03.github.io/pythonst/python_st_00.html">
1장. Python 입문
<i class="exc-trigger fa"></i>
</a>
<ul class="articles">
<li class="chapter " data-level="1.2.1" data-path="basics/01-hello-javascript.html">
<a href="https://bluecow03.github.io/pythonst/python_st_01.html">
01. Hello Python
</a>
</li>
<li class="chapter " data-level="1.2.2" data-path="basics/02-variables.html">
<a href="https://bluecow03.github.io/pythonst/python_st_02.html">
02. 변수와 입출력
</a>
</li>
<li class="chapter " data-level="1.2.3" data-path="basics/03-operator.html">
<a href="https://bluecow03.github.io/pythonst/python_st_03.html">
03. 연산자
</a>
</li>
<li class="chapter " data-level="1.2.4" data-path="basics/04-conditions.html">
<a href="https://bluecow03.github.io/pythonst/python_st_04.html">
04. 배열
</a>
</li>
<li class="chapter " data-level="1.2.5" data-path="basics/05-function.html">
<a href="https://bluecow03.github.io/pythonst/python_st_05.html">
05. 조건문
</a>
</li>
<li class="chapter expanded" data-level="1.2.6" data-path="basics/06-object.html">
<a href="https://bluecow03.github.io/pythonst/python_st_06.html">
06. 반복문
</a>
</li>
<li class="chapter " data-level="1.2.7" data-path="basics/07-array.html">
<a href="https://bluecow03.github.io/pythonst/python_st_07.html">
07. 함수
</a>
</li>
<li class="chapter " data-level="1.2.8" data-path="basics/08-loop.html">
<a href="https://bluecow03.github.io/pythonst/python_st_08.html">
08. 객체
</a>
</li>
<li class="chapter " data-level="1.2.9" data-path="basics/09-array-functions.html">
<a href="https://bluecow03.github.io/pythonst/python_st_09.html">
09. 클래스
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.3" data-path="useful/">
<a href="https://bluecow03.github.io/pythonst/python_qu_00.html">
2장. Python 간단 퀴즈
<i class="exc-trigger fa"></i>
</a>
<ul class="articles">
<li class="chapter " data-level="1.3.1" data-path="useful/01-ternary.html">
<a href="https://bluecow03.github.io/pythonst/python_qu_01.html">
01. 입력을 통한 사칙연산
</a>
</li>
<li class="chapter " data-level="1.3.2" data-path="useful/02-truthy-and-falsy.html">
<a href="https://bluecow03.github.io/pythonst/python_qu_02.html">
02. if-elif문 활용
</a>
</li>
<li class="chapter " data-level="1.3.3" data-path="useful/03-short-circuiting.html">
<a href="https://bluecow03.github.io/pythonst/python_qu_03.html">
03. 반복문 활용
</a>
</li>
<li class="chapter " data-level="1.3.4" data-path="useful/04-default-function-params.html">
<a href="https://bluecow03.github.io/pythonst/python_qu_04.html">
04. 중복 반복문
</a>
</li>
<li class="chapter " data-level="1.3.5" data-path="useful/05-smarter-conditions.html">
<a href="https://bluecow03.github.io/pythonst/python_qu_05.html">
05. 반복문과 if문 혼합 사용
</a>
</li>
<li class="chapter " data-level="1.3.6" data-path="useful/06-destructuring.html">
<a href="https://bluecow03.github.io/pythonst/python_qu_06.html">
06. 함수 활용
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com/" target="blank" class="gitbook-link" style="display: none;">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<a class="btn pull-left js-toolbar-action" aria-label="" href="https://bluecow03.github.io/pythonst">
<i class="fa fa-align-justify"></i>
</a>
<a class="btn pull-right js-toolbar-action" aria-label="GitHub" href="https://bluecow03.github.io/pythonst">
<i class="fa fa-github"></i>
</a>
<a class="btn pull-left js-toolbar-action" aria-label="" href="https://bluecow03.github.io/pythonst">
<i class="fa fa-edit"></i>
수정 요청하기
</a>
<div class="dropdown pull-right js-toolbar-action">
<a class="btn toggle-dropdown" aria-label="Share" href="https://bluecow03.github.io/pythonst">
<i class="fa fa-share-alt"></i>
</a>
<div class="dropdown-menu dropdown-left">
<div class="dropdown-caret">
<span class="caret-outer"></span>
<span class="caret-inner"></span>
</div>
<div class="buttons">
<button class="button size-5 ">Facebook</button>
<button class="button size-5 ">Google+</button>
<button class="button size-5 ">Twitter</button>
<button class="button size-5 ">Weibo</button>
<button class="button size-5 ">Instapaper</button>
</div>
</div>
</div>
<a class="btn pull-right js-toolbar-action" aria-label="" href="https://bluecow03.github.io/pythonst">
<i class="fa fa-facebook"></i>
</a>
<a class="btn pull-right js-toolbar-action" aria-label="" href="https://bluecow03.github.io/pythonst">
<i class="fa fa-twitter"></i>
</a>
<div class="dropdown pull-left font-settings js-toolbar-action">
<a class="btn toggle-dropdown" aria-label="Font Settings" href="https://bluecow03.github.io/pythonst">
<i class="fa fa-font"></i>
</a>
<div class="dropdown-menu dropdown-right">
<div class="dropdown-caret">
<span class="caret-outer"></span>
<span class="caret-inner"></span>
</div>
<div class="buttons">
<button class="button size-2 font-reduce">A</button>
<button class="button size-2 font-enlarge">A</button>
</div>
<div class="buttons">
<button class="button size-2 ">Serif</button>
<button class="button size-2 ">Sans</button>
</div>
<div class="buttons">
<button class="button size-3 ">White</button>
<button class="button size-3 ">Sepia</button>
<button class="button size-3 ">Night</button>
</div>
</div>
</div>
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="https://bluecow03.github.io/pythonst">Python</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="조건문">조건문</h1>
<p>
이번에는 조건문에 대하여 알아보겠습니다.<br>
조건문은 프로그래밍 언어에서 특정 조건이 만족됐을 때 안에 있는 코드를 실행하도록 하는 문법입니다.
</p>
<h2 id="IF 문">IF 문</h2>
<p>
IF문은 '~일 때 ~을 해라'라는 문법입니다. 예를 들어, '라면을 좋아하면 "라면 좋아!"를 출력하라'라는 문장을
출력하게 만드는 문법입니다. 그러면 실습을 통해서 알아볼까요?
</p>
<img src="./pictures/python_st_05/st_05_01.JPG" alt="not found" width="auto" height="auto">
<p>
실습을 통해서 볼 수 있듯이 '라면 좋아!'를 출력 되었습니다. <br>
하지만, 여기서 like의 값을 '고기'로 바꾸면 어떻게 될까요?
</p>
<img src="./pictures/python_st_05/st_05_02.JPG" alt="not found" width="auto" height="auto">
<p>
결과는 보시는 바와 같이 아무것도 출력이 되지 않습니다.<br>
실습에서 알 수 있듯이 IF문은 조건이 만족 되었을 때에만 안에 있는 코드를 실행하는 문법입니다.
</p>
<img src="./pictures/python_st_05/st_05_03.JPG" alt="not found" width="auto" height="auto">
<p>
문법으로는 이렇게 됩니다.
</p>
<p>
그러면 다른 실습을 통해서 더욱 자세히 알아볼까요?
</p>
<img src="./pictures/python_st_05/st_05_04.JPG" alt="not found" width="auto" height="auto">
<p>
실습에서 x는 1과 같아서 1을 출력하고 x의 값을 2로 바꾼 다음 IF문을 빠져나와 2의 값을 출력 하였습니다.<br>
그렇다면 x가 1이 아니면 어떻게 될까요?
</p>
<img src="./pictures/python_st_05/st_05_05.JPG" alt="not found" width="auto" height="auto">
<p>
위의 결과를 보듯이 '3'만 출력이 되는 것을 보실 수 있습니다.
</p>
<h2 id="IF-ELSE 문">IF-ELSE 문</h2>
<p>
IF-ELSE문은 "~하다면 ~하고, 그렇지 않다면 ~해라"라는 문법입니다.<br>
실습을 통해 알아볼까요?
</p>
<img src="./pictures/python_st_05/st_05_06.JPG" alt="not found" width="auto" height="auto">
<p>
실습을 통해서 알 수 있듯이 x의 값은 2이므로 esle 안에 있는 "x의 값이 1이 아닙니다."라는 문장이 출력이 되었습니다.<br>
이렇게 조건이 만족할 때와 만족하지 않을 때 서로 다른 코드를 실행해야 된다면 IF-ELSE 문을 사용 할 수 있습니다.
</p>
<h2 id="IF-ELIF 문">IF-ELIF 문</h2>
<p>
IF-ELIF 문은 여러 조건에 따른 작업을 해야 할 때 사용합니다.<br>
실습을 통해서 알아보겠습니다.
</p>
<img src="./pictures/python_st_05/st_05_07.JPG" alt="not found" width="auto" height="auto">
<p>
결과를 보듯이 x의 값은 3이므로, 'x의 값은 1도 아니고 2도 아닌 3 입니다.'라는 문장이 출력되는 것을 볼 수 있습니다.
</p>
<p>
이번에는 조건문에 대하여 알아보았습니다. 앞으로 프로그래밍을 하면서 조건문과 반복문은 정말 많이
쓰이기에 잘 기억해두시면 앞으로 프로그래밍을 할 때 많은 도움이 될 것입니다.
</p>
<script>
function attachComments() {
const el = document.querySelector('.markdown-section');
if (!el) return;
const script = document.createElement('script');
script.src = 'https://utteranc.es/client.js';
script.setAttribute('repo', 'velopert/learnjs');
script.setAttribute('issue-term', 'title');
script.setAttribute('crossorigin', 'anonymous');
script.setAttribute('label', 'comments');
el.appendChild(script);
}
setTimeout(attachComments, 100);
</script>
<div class="utterances">
<iframe class="utterances-frame" title="Comments" scrolling="no" src="./python.html" loading="lazy"></iframe>
</div>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title">
<span class="search-results-count"></span> results matching "<span class="search-query"></span>"
</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class="search-query"></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="https://bluecow03.github.io/pythonst/python_st_04.html" class="navigation navigation-prev " aria-label="Previous page: 04. 배열">
<i class="fa fa-angle-left"></i>
</a>
<a href="https://bluecow03.github.io/pythonst/python_st_06.html" class="navigation navigation-next navigation-unique" aria-label="Next page: 06. 반복문" style="margin-right: 17px;">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged(
{"page":{
"title":"Python 입문",
"level":"1.1",
"depth":1,
"next":{
"title":"1장. python 입문",
"level":"1.2",
"depth":1,
"path":"basics/README.md",
"ref":"./basics/README.md",
"articles":[{
"title":"01. Hello Python",
"level":"1.2.1",
"depth":2,
"articles":[]
},
{
"title":"02. 변수와 입출력",
"level":"1.2.2",
"depth":2,
"articles":[]
},
{
"title":"03. 연산자",
"level":"1.2.3",
"depth":2,
"articles":[]
},
{
"title":"04. 배열",
"level":"1.2.4",
"depth":2,
"articles":[]
},
{
"title":"05. 조건문",
"level":"1.2.5",
"depth":2,
"articles":[]
},
{
"title":"06. 반복문",
"level":"1.2.6",
"depth":2,
"articles":[]
},
{
"title":"07. 함수",
"level":"1.2.7",
"depth":2,
"articles":[]
},
{
"title":"08. 객체",
"level":"1.2.8",
"depth":2,
"articles":[]
},
{"title":"09. 클래스",
"level":"1.2.9",
"depth":2,
"articles":[]
}]
},
"dir":"ltr"},
"config":{
"gitbook":"*",
"theme":"default",
"variables":{},
"plugins":[
"collapsible-chapters",
"comment",
"hide-published-with",
"github",
"edit-link"
],
"pluginsConfig":{
"github":{
"url":"https://github.com/BlueCow03/pythonst"
},
"search":{},
"collapsible-chapters":{},
"lunr":{
"maxIndexSize":1000000,
"ignoreSpecialCharacters":false
},
"hide-published-with":{},
"fontsettings":{
"theme":"white",
"family":"sans",
"size":2
},
"highlight":{},
"sharing":{
"facebook":true,
"twitter":true,
"vk":false,
"all":["facebook","twitter"]
},
"edit-link":{
"label":"수정 요청하기",
"base":"https://github.com/BlueCow03/pythonst/edit/master"
},
"theme-default":{
"styles":{
"website":"styles/website.css",
"pdf":"styles/pdf.css",
"epub":"styles/epub.css",
"mobi":"styles/mobi.css",
"ebook":"styles/ebook.css",
"print":"styles/print.css"
},
"showLevel":false
},
"comment":{}
},
"structure":{
"langs":"LANGS.md",
"readme":"README.md",
"glossary":"GLOSSARY.md",
"summary":"SUMMARY.md"
},
"pdf":{
"pageNumbers":true,
"fontSize":12,
"fontFamily":"Arial",
"paperSize":"a4",
"chapterMark":"pagebreak",
"pageBreaksBefore":"/",
"margin":{
"right":62,
"left":62,
"top":56,
"bottom":56}
},
"styles":{
"website":"styles/website.css",
"pdf":"styles/pdf.css",
"epub":"styles/epub.css",
"mobi":"styles/mobi.css",
"ebook":"styles/ebook.css",
"print":"styles/print.css"}
},
"file":{
"path":"README.md",
"mtime":"2019-05-18T02:44:31.008Z",
"type":"markdown"
},
"gitbook":{
"version":"3.2.3",
"time":"2019-06-09T12:51:25.214Z"
},
"basePath":".",
"book":{"language":""}
}
);
});
</script>
</div>
<script src="https://bluecow03.github.io/pythonst/python/gitbook.js"></script>
<script src="https://bluecow03.github.io/pythonst/python/theme.js"></script>
<script src="https://bluecow03.github.io/pythonst/python/collapsible-chapters.js"></script>
<script src="https://bluecow03.github.io/pythonst/python/plugin.js"></script>
<script src="https://bluecow03.github.io/pythonst/python/plugin(1).js"></script>
<script src="https://bluecow03.github.io/pythonst/python/plugin(2).js"></script>
<script src="https://bluecow03.github.io/pythonst/python/search-engine.js"></script>
<script src="https://bluecow03.github.io/pythonst/python/search.js"></script>
<script src="https://bluecow03.github.io/pythonst/python/lunr.min.js"></script>
<script src="https://bluecow03.github.io/pythonst/python/search-lunr.js"></script>
<script src="https://bluecow03.github.io/pythonst/python/buttons.js"></script>
<script src="https://bluecow03.github.io/pythonst/python/fontsettings.js"></script>
</body>
</html>