From 870fe340a946b28abf7bc5b399e1bc7f5dc102f0 Mon Sep 17 00:00:00 2001 From: jshyun1 Date: Wed, 7 Dec 2022 14:34:53 +0900 Subject: [PATCH 01/21] kor ver --- lang-ko/readme_ko.md | 454 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 454 insertions(+) create mode 100644 lang-ko/readme_ko.md diff --git a/lang-ko/readme_ko.md b/lang-ko/readme_ko.md new file mode 100644 index 00000000..770ee592 --- /dev/null +++ b/lang-ko/readme_ko.md @@ -0,0 +1,454 @@ +# ๐Ÿ 30 Days Of Python + +|# Day | Topics | +|------|:---------------------------------------------------------:| +| 01 | [Introduction](./readme.md)| +| 02 | [Variables, Built-in Functions](./02_Day_Variables_builtin_functions/02_variables_builtin_functions.md)| +| 03 | [Operators](./03_Day_Operators/03_operators.md)| +| 04 | [Strings](./04_Day_Strings/04_strings.md)| +| 05 | [Lists](./05_Day_Lists/05_lists.md)| +| 06 | [Tuples](./06_Day_Tuples/06_tuples.md)| +| 07 | [Sets](./07_Day_Sets/07_sets.md)| +| 08 | [Dictionaries](./08_Day_Dictionaries/08_dictionaries.md)| +| 09 | [Conditionals](./09_Day_Conditionals/09_conditionals.md)| +| 10 | [Loops](./10_Day_Loops/10_loops.md)| +| 11 | [Functions](./11_Day_Functions/11_functions.md)| +| 12 | [Modules](./12_Day_Modules/12_modules.md)| +| 13 | [List Comprehension](./13_Day_List_comprehension/13_list_comprehension.md)| +| 14 | [Higher Order Functions](./14_Day_Higher_order_functions/14_higher_order_functions.md)| +| 15 | [Python Type Errors](./15_Day_Python_type_errors/15_python_type_errors.md)| +| 16 | [Python Date time](./16_Day_Python_date_time/16_python_datetime.md) | +| 17 | [Exception Handling](./17_Day_Exception_handling/17_exception_handling.md)| +| 18 | [Regular Expressions](./18_Day_Regular_expressions/18_regular_expressions.md)| +| 19 | [File Handling](./19_Day_File_handling/19_file_handling.md)| +| 20 | [Python Package Manager](./20_Day_Python_package_manager/20_python_package_manager.md)| +| 21 | [Classes and Objects](./21_Day_Classes_and_objects/21_classes_and_objects.md)| +| 22 | [Web Scraping](./22_Day_Web_scraping/22_web_scraping.md)| +| 23 | [Virtual Environment](./23_Day_Virtual_environment/23_virtual_environment.md)| +| 24 | [Statistics](./24_Day_Statistics/24_statistics.md)| +| 25 | [Pandas](./25_Day_Pandas/25_pandas.md)| +| 26 | [Python web](./26_Day_Python_web/26_python_web.md)| +| 27 | [Python with MongoDB](./27_Day_Python_with_mongodb/27_python_with_mongodb.md)| +| 28 | [API](./28_Day_API/28_API.md)| +| 29 | [Building API](./29_Day_Building_API/29_building_API.md)| +| 30 | [Conclusions](./30_Day_Conclusions/30_conclusions.md)| + +๐Ÿงก๐Ÿงก๐Ÿงก HAPPY CODING ๐Ÿงก๐Ÿงก๐Ÿงก + +
+Support the author to create more educational materials
+Paypal Logo +
+ +
+

30 Days Of Python: Day 1 - Introduction

+ + + + + Twitter Follow + + + Author: + Asabeneh Yetayeh
+ Second Edition: July, 2021 +
+
+ + +[Day 2 >>](./02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) + +![30DaysOfPython](./images/30DaysOfPython_banner3@2x.png) + +- [๐Ÿ 30 Days Of Python](#-30-days-of-python) +- [๐Ÿ“˜ Day 1](#-day-1) + - [ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค](#welcome) + - [์†Œ๊ฐœ](#introduction) + - [์™œ Python์ด๋Š๋ƒ?](#why-python-) + - [ํ™˜๊ฒฝ ์„ค์ •](#environment-setup) + - [Python ์„ค์น˜](#installing-python) + - [Python ์…ธ](#python-shell) + - [Visual Studio Code ์„ค์น˜](#installing-visual-studio-code) + - [visual studio code๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ](#how-to-use-visual-studio-code) + - [Python ๊ธฐ๋ณธ](#basic-python) + - [Python ๊ตฌ๋ฌธ](#python-syntax) + - [Python ๋“ค์—ฌ์“ฐ๊ธฐ](#python-indentation) + - [์ฃผ์„](#comments) + - [๋ฐ์ดํ„ฐ ํƒ€์ž…](#data-types) + - [Number](#number) + - [String](#string) + - [Booleans](#booleans) + - [List](#list) + - [Dictionary](#dictionary) + - [Tuple](#tuple) + - [Set](#set) + - [๋ฐ์ดํ„ฐ ํƒ€์ž… ์ฒดํฌ](#checking-data-types) + - [Python ํŒŒ์ผ](#python-file) + - [๐Ÿ’ป Exercises - Day 1](#-exercises---day-1) + - [Exercise: Level 1](#exercise-level-1) + - [Exercise: Level 2](#exercise-level-2) + - [Exercise: Level 3](#exercise-level-3) + +# ๐Ÿ“˜ Day 1 + +## ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค + +_30 days of Python_์— ์ฐธ์—ฌํ•˜๊ธฐ๋กœ ๊ฒฐ์ •ํ•˜์‹  ๊ฒƒ์„ **์ถ•ํ•˜๋“œ๋ฆฝ๋‹ˆ๋‹ค**. ์ด ์ฑŒ๋ฆฐ์ง€์—์„œ๋Š” Python ํ”„๋กœ๊ทธ๋ž˜๋จธ๊ฐ€ ๋˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ๋ชจ๋“  ๊ฒƒ๊ณผ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ์ „์ฒด ๊ฐœ๋…์„ ๋ฐฐ์šฐ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ฑŒ๋ฆฐ์ง€๊ฐ€ ๋๋‚˜๋ฉด _30DaysOfPython_ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ฑŒ๋ฆฐ์ง€ ์ธ์ฆ์„œ๋ฅผ ๋ฐ›๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. + +์ฑŒ๋ฆฐ์ง€์— ์ ๊ทน์ ์œผ๋กœ ์ฐธ์—ฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด [30DaysOfPython challenge](https://t.me/ThirtyDaysOfPython) ํ…”๋ ˆ๊ทธ๋žจ ๊ทธ๋ฃน์— ๊ฐ€์ž…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +## ์†Œ๊ฐœ + +Python์€ ๋ฒ”์šฉ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ์œ„ํ•œ ๊ณ ๊ธ‰ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ž…๋‹ˆ๋‹ค. ์˜คํ”ˆ ์†Œ์Šค, ์ธํ„ฐํ”„๋ฆฌํ„ฐ, ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ž…๋‹ˆ๋‹ค. Python์€ ๋„ค๋œ๋ž€๋“œ ํ”„๋กœ๊ทธ๋ž˜๋จธ Guido van Rossum์ด ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. Python ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์˜ ์ด๋ฆ„์€ ์˜๊ตญ ์Šค์ผ€์น˜ ์ฝ”๋ฏธ๋”” ์‹œ๋ฆฌ์ฆˆ *Month Python's Flying Circus* ์—์„œ ํŒŒ์ƒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ฒซ ๋ฒˆ์งธ ๋ฒ„์ „์€ 1991๋…„ 2์›” 20์ผ์— ์ถœ์‹œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด 30์ผ๊ฐ„์˜ Python ์ฑŒ๋ฆฐ์ง€๋Š” ์ตœ์‹  ๋ฒ„์ „์˜ Python์ธ Python 3๋ฅผ ์ฐจ๊ทผ์ฐจ๊ทผ ๋ฐฐ์šธ ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ค„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ฃผ์ œ๋Š” 30์ผ๋กœ ๋‚˜๋‰˜๋ฉฐ, ๋งค์ผ ์ดํ•ดํ•˜๊ธฐ ์‰ฌ์šด ์„ค๋ช…, ์‹ค์ œ ์‚ฌ๋ก€, ๋งŽ์€ ์‹ค์Šต ๋ฐ ํ”„๋กœ์ ํŠธ๊ฐ€ ํฌํ•จ๋œ ์—ฌ๋Ÿฌ ์ฃผ์ œ๊ฐ€ ํฌํ•จ๋ฉ๋‹ˆ๋‹ค. + +์ด ์ฑŒ๋ฆฐ์ง€๋Š” Python ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋ฅผ ๋ฐฐ์šฐ๊ณ ์ž ํ•˜๋Š” ์ดˆ๋ณด์ž์™€ ์ „๋ฌธ๊ฐ€๋ฅผ ์œ„ํ•ด ๊ณ ์•ˆ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ฑŒ๋ฆฐ์ง€๋ฅผ ์™„๋ฃŒํ•˜๋Š” ๋ฐ 30~100์ผ์ด ์†Œ์š”๋  ์ˆ˜ ์žˆ์œผ๋ฉฐ ํ…”๋ ˆ๊ทธ๋žจ ๊ทธ๋ฃน์— ์ ๊ทน์ ์œผ๋กœ ์ฐธ์—ฌํ•˜๋Š” ์‚ฌ๋žŒ๋“ค์ด ์ฑŒ๋ฆฐ์ง€๋ฅผ ์™„๋ฃŒํ•  ํ™•๋ฅ ์ด ๋†’์Šต๋‹ˆ๋‹ค. +์‹œ๊ฐ์  ํ•™์Šต์ž์ด๊ฑฐ๋‚˜ ๋™์˜์ƒ์„ ์„ ํ˜ธํ•˜๋Š” ๊ฒฝ์šฐ ์ด [์™„์ „ ์ดˆ๋ณด๋ฅผ ์œ„ํ•œ Python ๋™์˜์ƒ](https://www.youtube.com/watch?v=11OYpBrhdyM)์œผ๋กœ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +## ์™œ Python์ด๋Š๋ƒ? + +์ธ๊ฐ„์˜ ์–ธ์–ด์— ๋งค์šฐ ๊ฐ€๊น๊ณ  ๋ฐฐ์šฐ๊ธฐ ์‰ฝ๊ณ  ์‚ฌ์šฉํ•˜๊ธฐ ์‰ฌ์šด ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ž…๋‹ˆ๋‹ค. +Python์€ ๋‹ค์–‘ํ•œ ์‚ฐ์—… ๋ฐ ํšŒ์‚ฌ(Google ํฌํ•จ)์—์„œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์›น ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ, ๋ฐ์Šคํฌํ†ฑ ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ, ์‹œ์Šคํ…œ ๊ด€๋ฆฌ ๋ฐ ๊ธฐ๊ณ„ ํ•™์Šต ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๊ฐœ๋ฐœํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. Python์€ ๋ฐ์ดํ„ฐ ๊ณผํ•™ ๋ฐ ๊ธฐ๊ณ„ ํ•™์Šต ์ปค๋ฎค๋‹ˆํ‹ฐ์—์„œ ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๋Š” ์–ธ์–ด์ž…๋‹ˆ๋‹ค. ์ด๊ฒƒ์ด Python ํ•™์Šต์„ ์‹œ์ž‘ํ•˜๋„๋ก ์„ค๋“ํ•˜๊ธฐ์— ์ถฉ๋ถ„ํ•˜๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค. Python์€ ์„ธ์ƒ์„ ์ง€๋ฐฐํ•˜๊ณ  ์žˆ์œผ๋‹ˆ ์ง€๋ฐฐ ๋‹นํ•˜๊ธฐ ์ „์— Python์„ ์ง€๋ฐฐํ•˜์‹ญ์‹œ์˜ค. +## ํ™˜๊ฒฝ ์„ค์ • + +### Python ์„ค์น˜ + +Python ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋ฉด Python์„ ์„ค์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Python์„ [๋‹ค์šด๋กœ๋“œ](https://www.python.org/)ํ•ฉ์‹œ๋‹ค. +Windows ์‚ฌ์šฉ์ž์ธ ๊ฒฝ์šฐ. ๋นจ๊ฐ„์ƒ‰ ๋™๊ทธ๋ผ๋ฏธ ์นœ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. + + + +macOS ์‚ฌ์šฉ์ž์ธ ๊ฒฝ์šฐ. ๋นจ๊ฐ„์ƒ‰ ๋™๊ทธ๋ผ๋ฏธ ์นœ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. + +[![Windows์—์„œ ์„ค์น˜](./images/installing_on_windows.png)](https://www.python.org/) + +Python์ด ์„ค์น˜๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋ ค๋ฉด ์žฅ์น˜ ํ„ฐ๋ฏธ๋„์— ๋‹ค์Œ ๋ช…๋ น์„ ์ž‘์„ฑํ•˜์‹ญ์‹œ์˜ค. + +```shell +python --version +``` + +![Python Version](./images/python_versio.png) + +ํ„ฐ๋ฏธ๋„์—์„œ ๋ณด์‹œ๋‹ค์‹œํ”ผ ์ €๋Š” ํ˜„์žฌ _Python 3.7.5_ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ท€ํ•˜์˜ Python ๋ฒ„์ „์€ ๋‚ด ๋ฒ„์ „๊ณผ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์ง€๋งŒ 3.6 ์ด์ƒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Python ๋ฒ„์ „์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค๋ฉด ์ž˜ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด์ œ ์ปดํ“จํ„ฐ์— Python์ด ์„ค์น˜๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ์„น์…˜์œผ๋กœ ๊ณ„์† ์ง„ํ–‰ํ•˜์‹ญ์‹œ์˜ค. + +### Python ์…ธ + +Python์€ ํ•ด์„๋œ ์Šคํฌ๋ฆฝํŒ… ์–ธ์–ด์ด๋ฏ€๋กœ ์ปดํŒŒ์ผํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ์ฝ”๋“œ๋ฅผ ํ•œ ์ค„์”ฉ ์‹คํ–‰ํ•œ๋‹ค๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค. Python์€ _Python Shell(Python Interactive Shell)_๊ณผ ํ•จ๊ป˜ ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค. ๋‹จ์ผ Python ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ์–ป๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. + +Python Shell์€ ์‚ฌ์šฉ์ž์˜ Python ์ฝ”๋“œ๋ฅผ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค. ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์ฝ”๋“œ๋ฅผ ํ•ด์„ํ•˜์—ฌ ๋‹ค์Œ ์ค„์— ๊ฒฐ๊ณผ๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค. +ํ„ฐ๋ฏธ๋„์ด๋‚˜ ๋ช…๋ น ํ”„๋กฌํ”„ํŠธ(cmd)๋ฅผ ์—ด๊ณ  ์“ฐ๊ธฐ: + +```shell +python +``` + +![Python Scripting Shell](./images/opening_python_shell.png) + +Python ๋Œ€ํ™”ํ˜• ์…ธ์ด ์—ด๋ฆฌ๊ณ  Python ์ฝ”๋“œ(Python ์Šคํฌ๋ฆฝํŠธ)๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ๋ฅผ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค. ๊ธฐํ˜ธ >>> ์˜†์— Python ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  Enter๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค. +Python ์Šคํฌ๋ฆฝํŒ… ์…ธ์—์„œ ์ฒซ ๋ฒˆ์งธ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +![Python script on Python shell](./images/adding_on_python_shell.png) + +ํ›Œ๋ฅญํ•ฉ๋‹ˆ๋‹ค. Python ๋Œ€ํ™”ํ˜• ์…ธ์—์„œ ์ฒซ ๋ฒˆ์งธ Python ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. Python ๋Œ€ํ™”ํ˜• ์…ธ์„ ์–ด๋–ป๊ฒŒ ๋‹ซ์Šต๋‹ˆ๊นŒ? +์…ธ์„ ๋‹ซ์œผ๋ ค๋ฉด ๊ธฐํ˜ธ ์˜†์— >> **exit()** ๋ช…๋ น์„ ์ž‘์„ฑํ•˜๊ณ  Enter ํ‚ค๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค. + +![Exit from python shell](./images/exit_from_shell.png) + +์ด์ œ Python ๋Œ€ํ™”ํ˜• ์…ธ์„ ์—ฌ๋Š” ๋ฐฉ๋ฒ•๊ณผ ์ข…๋ฃŒํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•˜์Šต๋‹ˆ๋‹ค. + +Python์€ Python์ด ์ดํ•ดํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ๊ฒฐ๊ณผ๋ฅผ ์ œ๊ณตํ•˜๊ณ  ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์˜ค๋ฅ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๊ณ ์˜์ ์ธ ์‹ค์ˆ˜๋ฅผ ํ•˜๊ณ  Python์ด ๋ฌด์—‡์„ ๋ฐ˜ํ™˜ํ•˜๋Š”์ง€ ๋ด…์‹œ๋‹ค. + +![Invalid Syntax Error](./images/invalid_syntax_error.png) + +๋ฐ˜ํ™˜๋œ ์˜ค๋ฅ˜์—์„œ ๋ณผ ์ˆ˜ ์žˆ๋“ฏ์ด Python์€ ์šฐ๋ฆฌ๊ฐ€ ์ €์ง€๋ฅธ ์‹ค์ˆ˜์™€ _Syntax Error: invalid syntax_๋ฅผ ์•Œ๊ณ  ์žˆ์„ ์ •๋„๋กœ ์˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค. Python์—์„œ x๋ฅผ ๊ณฑ์…ˆ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ (x)๊ฐ€ Python์—์„œ ์œ ํšจํ•œ ๊ตฌ๋ฌธ์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ตฌ๋ฌธ ์˜ค๋ฅ˜์ž…๋‹ˆ๋‹ค. (**x**) ๋Œ€์‹  ๊ณฑ์…ˆ์— ๋ณ„ํ‘œ(*)๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋ฐ˜ํ™˜๋œ ์˜ค๋ฅ˜๋Š” ์ˆ˜์ •ํ•ด์•ผ ํ•  ์‚ฌํ•ญ์„ ๋ช…ํ™•ํ•˜๊ฒŒ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. + +ํ”„๋กœ๊ทธ๋žจ์—์„œ ์˜ค๋ฅ˜๋ฅผ ์‹๋ณ„ํ•˜๊ณ  ์ œ๊ฑฐํ•˜๋Š” ํ”„๋กœ์„ธ์Šค๋ฅผ *๋””๋ฒ„๊น…*์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. **x** ๋Œ€์‹  *๋ฅผ ๋„ฃ์–ด ๋””๋ฒ„๊น…ํ•ด ๋ด…์‹œ๋‹ค. + +![Fixing Syntax Error](./images/fixing_syntax_error.png) + +๋ฒ„๊ทธ๊ฐ€ ์ˆ˜์ •๋˜์—ˆ๊ณ  ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋˜์—ˆ์œผ๋ฉฐ ์˜ˆ์ƒํ–ˆ๋˜ ๊ฒฐ๊ณผ๋ฅผ ์–ป์—ˆ์Šต๋‹ˆ๋‹ค. ํ”„๋กœ๊ทธ๋ž˜๋จธ๋กœ์„œ ๋งค์ผ ์ด๋Ÿฌํ•œ ์ข…๋ฅ˜์˜ ์˜ค๋ฅ˜๋ฅผ ๋ณด๊ฒŒ ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋””๋ฒ„๊น… ๋ฐฉ๋ฒ•์„ ์•„๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ๋””๋ฒ„๊น…์„ ์ž˜ํ•˜๋ ค๋ฉด ์–ด๋–ค ์ข…๋ฅ˜์˜ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ๋Š”์ง€ ์ดํ•ดํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” Python ์˜ค๋ฅ˜ ์ค‘ ์ผ๋ถ€๋Š” *SyntaxError*, *IndexError*, *NameError*, *ModuleNotFoundError*, *KeyError*, *ImportError*, *AttributeError*, *TypeError*, *ValueError*, *ZeroDivisionError* ๋“ฑ์ž…๋‹ˆ๋‹ค. ์ดํ›„ ์„น์…˜์—์„œ ๋‹ค๋ฅธ Python **_์˜ค๋ฅ˜ ์œ ํ˜•_**์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณผ ๊ฒƒ์ž…๋‹ˆ๋‹ค. + +Python ๋Œ€ํ™”ํ˜• ์…ธ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋” ์—ฐ์Šตํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ํ„ฐ๋ฏธ๋„์ด๋‚˜ ๋ช…๋ น ํ”„๋กฌํ”„ํŠธ๋กœ ์ด๋™ํ•˜์—ฌ **python**์ด๋ผ๋Š” ๋‹จ์–ด๋ฅผ ์”๋‹ˆ๋‹ค. + +![Python Scripting Shell](./images/opening_python_shell.png) + +Python ๋Œ€ํ™”ํ˜• ์…ธ์ด ์—ด๋ฆฝ๋‹ˆ๋‹ค. ๋ช‡ ๊ฐ€์ง€ ๊ธฐ๋ณธ์ ์ธ ์ˆ˜ํ•™ ์—ฐ์‚ฐ(๋”ํ•˜๊ธฐ, ๋นผ๊ธฐ, ๊ณฑํ•˜๊ธฐ, ๋‚˜๋ˆ„๊ธฐ, ๋‚˜๋จธ์ง€, ์ง€์ˆ˜)์„ ์ˆ˜ํ–‰ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +Python ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ ์ „์— ๋จผ์ € ๋ช‡ ๊ฐ€์ง€ ์ˆ˜ํ•™์„ ์ˆ˜ํ–‰ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค: + +- 2 + 3 = 5 +- 3 - 2 = 1 +- 3 \* 2 = 6 +- 3 / 2 = 1.5 +- 3 ^ 2 = 3 x 3 = 9 + +Python์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ถ”๊ฐ€ ์ž‘์—…์ด ์žˆ์Šต๋‹ˆ๋‹ค: + +- 3 % 2 = 1 => ๋‚˜๋จธ์ง€๋ฅผ ๊ตฌํ•จ +- 3 // 2 = 1 => ๋‚˜๋จธ์ง€๋ฅผ ์ œ๊ฑฐ + +์œ„์˜ ์ˆ˜ํ•™์‹์„ Python ์ฝ”๋“œ๋กœ ๋ฐ”๊ฟ”๋ด…์‹œ๋‹ค. Python ์…ธ์ด ์—ด๋ ธ์œผ๋ฉฐ ์…ธ ๋งจ ์ฒ˜์Œ์— ์ฃผ์„์„ ์ž‘์„ฑํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +_comment_๋Š” Python์— ์˜ํ•ด ์‹คํ–‰๋˜์ง€ ์•Š๋Š” ์ฝ”๋“œ์˜ ์ผ๋ถ€์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ฝ”๋“œ๋ฅผ ๋” ์ฝ๊ธฐ ์‰ฝ๊ฒŒ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ์ฝ”๋“œ์— ์ผ๋ถ€ ํ…์ŠคํŠธ๋ฅผ ๋‚จ๊ธธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Python์€ ์ฃผ์„ ๋ถ€๋ถ„์„ ์‹คํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. Python์—์„œ ์ฃผ์„์€ ํ•ด์‹œ(#) ๊ธฐํ˜ธ๋กœ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. +์ด๊ฒƒ์ด Python์—์„œ ์ฃผ์„์„ ์ž‘์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค + +```shell + # ์ฃผ์„์€ ํ•ด์‹œ๋กœ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. + # (#) ์‹ฌ๋ณผ๋กœ ์‹œ์ž‘ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด๊ฒƒ์€ ํŒŒ์ด์ฌ ์ฃผ์„์ž…๋‹ˆ๋‹ค. +``` + +![Maths on python shell](./images/maths_on_python_shell.png) + +๋‹ค์Œ ์„น์…˜์œผ๋กœ ์ด๋™ํ•˜๊ธฐ ์ „์— Python ๋Œ€ํ™”ํ˜• ์…ธ์—์„œ ๋” ๋งŽ์€ ์—ฐ์Šต์„ ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์…ธ์—์„œ _exit()_๋ฅผ ์ž‘์„ฑํ•˜์—ฌ ์—ด๋ฆฐ ์…ธ์„ ๋‹ซ์•˜๋‹ค๊ฐ€ ๋‹ค์‹œ ์—ด์–ด Python ์…ธ์—์„œ ํ…์ŠคํŠธ๋ฅผ ์“ฐ๋Š” ๋ฐฉ๋ฒ•์„ ์—ฐ์Šตํ•ด ๋ด…์‹œ๋‹ค. + +![Writing String on python shell](./images/writing_string_on_shell.png) + +### Visual Studio Code ์„ค์น˜ + +Python ๋Œ€ํ™”ํ˜• ์…ธ์€ ์ž‘์€ ์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋ฅผ ์‹œ๋„ํ•˜๊ณ  ํ…Œ์ŠคํŠธํ•˜๋Š” ๋ฐ ์ ํ•ฉํ•˜์ง€๋งŒ ํฐ ํ”„๋กœ์ ํŠธ์—๋Š” ์ ํ•ฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์‹ค์ œ ์ž‘์—… ํ™˜๊ฒฝ์—์„œ ๊ฐœ๋ฐœ์ž๋Š” ๋‹ค์–‘ํ•œ ์ฝ”๋“œ ํŽธ์ง‘๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ด 30์ผ๊ฐ„์˜ Python ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ฑŒ๋ฆฐ์ง€์—์„œ๋Š” Visual Studio ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Visual Studio Code๋Š” ๋งค์šฐ ์ธ๊ธฐ ์žˆ๋Š” ์˜คํ”ˆ ์†Œ์Šค ํ…์ŠคํŠธ ํŽธ์ง‘๊ธฐ์ž…๋‹ˆ๋‹ค. ๋‚˜๋Š” vscode์˜ ํŒฌ์ด๊ณ  Visual Studio ์ฝ”๋“œ๋ฅผ [๋‹ค์šด๋กœ๋“œ](https://code.visualstudio.com/)ํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•˜๊ณ  ์‹ถ์ง€๋งŒ, ๋‹ค๋ฅธ ํŽธ์ง‘์ž๋ฅผ ์„ ํ˜ธํ•œ๋‹ค๋ฉด ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒƒ์„ ์ž์œ ๋กญ๊ฒŒ ๋”ฐ๋ฅด์‹ญ์‹œ์˜ค. + +[![Visual Studio Code](./images/vscode.png)](https://code.visualstudio.com/) + +Visual Studio Code๋ฅผ ์„ค์น˜ํ•˜์…จ๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. +๋น„๋””์˜ค๋ฅผ ์„ ํ˜ธํ•˜๋Š” ๊ฒฝ์šฐ Python์šฉ Visual Studio Code[๋น„๋””์˜ค ์ž์Šต์„œ](https://www.youtube.com/watch?v=bn7Cx4z-vSo)๋ฅผ ๋”ฐ๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +#### visual studio code๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ + +Visual Studio ์•„์ด์ฝ˜์„ ๋‘ ๋ฒˆ ํด๋ฆญํ•˜์—ฌ Visual Studio ์ฝ”๋“œ๋ฅผ ์—ฝ๋‹ˆ๋‹ค. ์—ด๋ฉด ์ด๋Ÿฐ ์ข…๋ฅ˜์˜ ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค. ๋ ˆ์ด๋ธ”์ด ์ง€์ •๋œ ์•„์ด์ฝ˜์„ ๋”ฐ๋ผํ•ด๋ณด์„ธ์š”. + +![Visual studio Code](./images/vscode_ui.png) + +๋ฐ”ํƒ• ํ™”๋ฉด์— 30DaysOfPython์ด๋ผ๋Š” ํด๋”๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ Visual Studio ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ฝ์‹œ๋‹ค. + +![Opening Project on Visual studio](./images/how_to_open_project_on_vscode.png) + +![Opening a project](./images/opening_project.png) + +ํŒŒ์ผ์„ ์—ด๋ฉด 30DaysOfPython ํ”„๋กœ์ ํŠธ์˜ ๋””๋ ‰ํ† ๋ฆฌ ๋‚ด๋ถ€์— ํŒŒ์ผ๊ณผ ํด๋”๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•œ ๋ฐ”๋กœ ๊ฐ€๊ธฐ๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์—์„œ ๋ณผ ์ˆ˜ ์žˆ๋“ฏ์ด ์ฒซ ๋ฒˆ์งธ ํŒŒ์ผ์ธ helloworld.py๋ฅผ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹น์‹ ๋„ ๋˜‘๊ฐ™์ด ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +![Creating a python file](./images/helloworld.png) + +ํ•˜๋ฃจ๋™์•ˆ ์˜ค๋ž˜ ์ฝ”๋”ฉ์„ ํ•œ ํ›„์— ์ฝ”๋“œ ํŽธ์ง‘๊ธฐ๋ฅผ ๋‹ซ๊ณ  ์‹ถ์Šต๋‹ˆ๊นŒ? ์ด๋ ‡๊ฒŒ ์—ด๋ฆฐ ํ”„๋กœ์ ํŠธ๋ฅผ ๋‹ซ์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. + +![Closing project](./images/closing_opened_project.png) + +์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ์„ค์ •์„ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค. ์ฝ”๋”ฉ์„ ์‹œ์ž‘ํ•ด ๋ด…์‹œ๋‹ค. + +## Python ๊ธฐ๋ณธ + +### Python ๊ตฌ๋ฌธ + +Python ์Šคํฌ๋ฆฝํŠธ๋Š” Python ๋Œ€ํ™”ํ˜• ์…ธ ๋˜๋Š” ์ฝ”๋“œ ํŽธ์ง‘๊ธฐ์—์„œ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Python ํŒŒ์ผ์˜ ํ™•์žฅ์ž๋Š” .py์ž…๋‹ˆ๋‹ค. + +### Python ๋“ค์—ฌ ์“ฐ๊ธฐ + +๋“ค์—ฌ์“ฐ๊ธฐ๋Š” ํ…์ŠคํŠธ์˜ ๊ณต๋ฐฑ์ž…๋‹ˆ๋‹ค. ๋งŽ์€ ์–ธ์–ด์—์„œ ๋“ค์—ฌ์“ฐ๊ธฐ๋Š” ์ฝ”๋“œ ๊ฐ€๋…์„ฑ์„ ๋†’์ด๋Š” ๋ฐ ์‚ฌ์šฉ๋˜์ง€๋งŒ Python์€ ๋“ค์—ฌ์“ฐ๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฝ”๋“œ ๋ธ”๋ก์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์—์„œ๋Š” ์ค‘๊ด„ํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋“ค์—ฌ์“ฐ๊ธฐ ๋Œ€์‹  ์ฝ”๋“œ ๋ธ”๋ก์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. Python ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ ํ”ํžˆ ๋ฐœ์ƒํ•˜๋Š” ๋ฒ„๊ทธ ์ค‘ ํ•˜๋‚˜๋Š” ์ž˜๋ชป๋œ ๋“ค์—ฌ์“ฐ๊ธฐ์ž…๋‹ˆ๋‹ค. + +![Indentation Error](./images/indentation.png) + +### ์ฃผ์„ + +์ฃผ์„์€ ์ฝ”๋“œ๋ฅผ ๋” ์ฝ๊ธฐ ์‰ฝ๊ฒŒ ๋งŒ๋“ค๊ณ  ์ฝ”๋“œ์— ์„ค๋ช…์„ ๋‚จ๊ธฐ๊ธฐ ์œ„ํ•ด ๋งค์šฐ ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. Python์€ ์ฝ”๋“œ์˜ ์ฃผ์„ ๋ถ€๋ถ„์„ ์‹คํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. +Python์—์„œ ํ•ด์‹œ(#)๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ชจ๋“  ํ…์ŠคํŠธ๋Š” ์ฃผ์„์ž…๋‹ˆ๋‹ค. + +**์˜ˆ์‹œ:ํ•œ ๋ฌธ์žฅ ์ฃผ์„** + +```shell + # This is the first comment + # This is the second comment + # Python is eating the world +``` + +**์˜ˆ์‹œ: ์—ฌ๋Ÿฌ ๋ฌธ์žฅ ์ฃผ์„** + +Triple quote can be used for multiline comment if it is not assigned to a variable + +```shell +"""This is multiline comment +multiline comment takes multiple lines. +python is eating the world +""" +``` + +### ๋ฐ์ดํ„ฐ ํƒ€์ž… + +Python์—๋Š” ์—ฌ๋Ÿฌ ์œ ํ˜•์˜ ๋ฐ์ดํ„ฐ ์œ ํ˜•์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์ธ ๊ฒƒ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ ์œ ํ˜•์€ ๋‹ค๋ฅธ ์„น์…˜์—์„œ ์ž์„ธํžˆ ๋‹ค๋ฃฐ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋‹น๋ถ„๊ฐ„ ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ์‚ดํŽด๋ณด๊ณ  ์ต์ˆ™ํ•ด์ง€๋„๋ก ํ•ฉ์‹œ๋‹ค. ์ง€๊ธˆ์€ ๋ช…ํ™•ํ•˜๊ฒŒ ์ดํ•ดํ•˜์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค. + +#### Number + +- Integer: ์ •์ˆ˜(์Œ์ˆ˜, ์˜ ๊ทธ๋ฆฌ๊ณ  ์–‘์ˆ˜) + ์˜ˆ์‹œ: + ... -3, -2, -1, 0, 1, 2, 3 ... +- Float: ์‹ญ์ง„์ˆ˜ + ์˜ˆ์‹œ + ... -3.5, -2.25, -1.0, 0.0, 1.1, 2.2, 3.5 ... +- Complex + ์˜ˆ์‹œ + 1 + j, 2 + 4j + +#### String + +์ž‘์€๋”ฐ์˜ดํ‘œ ๋˜๋Š” ํฐ๋”ฐ์˜ดํ‘œ ์•„๋ž˜์— ์žˆ๋Š” ํ•˜๋‚˜ ์ด์ƒ์˜ ๋ฌธ์ž ๋ชจ์Œ์ž…๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด์ด ๋‘ ๋ฌธ์žฅ ์ด์ƒ์ธ ๊ฒฝ์šฐ ์‚ผ์ค‘ ๋”ฐ์˜ดํ‘œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +**์˜ˆ์‹œ:** + +```py +'Asabeneh' +'Finland' +'Python' +'I love teaching' +'I hope you are enjoying the first day of 30DaysOfPython Challenge' +``` + +#### Boolean + +๋ถ€์šธ ๋ฐ์ดํ„ฐ ์œ ํ˜•์€ True ๋˜๋Š” False ๊ฐ’์ž…๋‹ˆ๋‹ค. T์™€ F๋Š” ํ•ญ์ƒ ๋Œ€๋ฌธ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +**์˜ˆ์‹œ:** + +```python + True # ๋ถˆ์ด ์ผœ์ ธ์žˆ๋‚˜์š”? ๊ทธ๋Ÿฌ๋ฉด ์ฐธ์ž…๋‹ˆ๋‹ค. + False # ๋ถˆ์ด ๊บผ์ ธ์žˆ๋‚˜์š”? ๊ทธ๋Ÿฌ๋ฉด ๊ฑฐ์ง“์ž…๋‹ˆ๋‹ค. +``` + +#### List + +Python ๋ฆฌ์ŠคํŠธ๋Š” ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ ์œ ํ˜• ํ•ญ๋ชฉ์„ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ์ •๋ ฌ๋œ ์ปฌ๋ ‰์…˜์ž…๋‹ˆ๋‹ค. ๋ฆฌ์ŠคํŠธ๋Š” JavaScript์˜ ๋ฐฐ์—ด๊ณผ ๋น„์Šทํ•ฉ๋‹ˆ๋‹ค. + +**Example:** + +```py +[0, 1, 2, 3, 4, 5] # ๋ชจ๋‘ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜• - ์ˆซ์ž ๋ฆฌ์ŠคํŠธ +['Banana', 'Orange', 'Mango', 'Avocado'] # ๋ชจ๋‘ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜• - ๋ฌธ์ž์—ด ๋ฆฌ์ŠคํŠธ(๊ณผ์ผ) +['Finland','Estonia', 'Sweden','Norway'] # ๋ชจ๋‘ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜• - ๋ฌธ์ž์—ด ๋ฆฌ์ŠคํŠธ(๊ตญ๊ฐ€) +['Banana', 10, False, 9.81] # ๋ฆฌ์ŠคํŠธ์˜ ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜• - ๋ฌธ์ž์—ด, ์ •์ˆ˜, ๋ถ€์šธ ๋ฐ ๋ถ€๋™ ์†Œ์ˆ˜์  +``` + +#### Dictionary + +Python ์‚ฌ์ „ ๊ฐœ์ฒด๋Š” ํ‚ค ๊ฐ’ ์Œ ํ˜•์‹์˜ ์ •๋ ฌ๋˜์ง€ ์•Š์€ ๋ฐ์ดํ„ฐ ๋ชจ์Œ์ž…๋‹ˆ๋‹ค. + +**Example:** + +```py +{ +'first_name':'Asabeneh', +'last_name':'Yetayeh', +'country':'Finland', +'age':250, +'is_married':True, +'skills':['JS', 'React', 'Node', 'Python'] +} +``` + +#### Tuple + +ํŠœํ”Œ์€ ๋ชฉ๋ก๊ณผ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜•์˜ ์ •๋ ฌ๋œ ๋ชจ์Œ์ด์ง€๋งŒ ํŠœํ”Œ์ด ์ƒ์„ฑ๋˜๋ฉด ์ˆ˜์ •ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๊ทธ๊ฒƒ๋“ค์€ ๋ณ€ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. + +**Example:** + +```py +('Asabeneh', 'Pawel', 'Brook', 'Abraham', 'Lidiya') # Names +``` + +```py +('Earth', 'Jupiter', 'Neptune', 'Mars', 'Venus', 'Saturn', 'Uranus', 'Mercury') # planets +``` + +#### Set + +์ง‘ํ•ฉ์€ ๋ชฉ๋ก ๋ฐ ํŠœํ”Œ๊ณผ ์œ ์‚ฌํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜•์˜ ๋ชจ์Œ์ž…๋‹ˆ๋‹ค. ๋ชฉ๋ก ๋ฐ ํŠœํ”Œ๊ณผ ๋‹ฌ๋ฆฌ ์ง‘ํ•ฉ์€ ์ˆœ์„œ๊ฐ€ ์ง€์ •๋œ ํ•ญ๋ชฉ ๋ชจ์Œ์ด ์•„๋‹™๋‹ˆ๋‹ค. ์ˆ˜ํ•™์—์„œ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ Python์—์„œ set์€ ๊ณ ์œ ํ•œ ํ•ญ๋ชฉ๋งŒ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. + +์ดํ›„ ์„น์…˜์—์„œ๋Š” ๊ฐ๊ฐ์˜ ๋ชจ๋“  Python ๋ฐ์ดํ„ฐ ์œ ํ˜•์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค. + +**Example:** + +```py +{2, 4, 3, 5} +{3.14, 9.81, 2.7} # order is not important in set +``` + +### ๋ฐ์ดํ„ฐ ํƒ€์ž… ์ฒดํฌ + +ํŠน์ • ๋ฐ์ดํ„ฐ/๋ณ€์ˆ˜์˜ ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด **type** ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ํ„ฐ๋ฏธ๋„์—์„œ ๋‹ค์–‘ํ•œ Python ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค: + +![Checking Data types](./images/checking_data_types.png) + +### Python ํŒŒ์ผ + +๋จผ์ € ํ”„๋กœ์ ํŠธ ํด๋”์ธ 30DaysOfPython์„ ์—ฝ๋‹ˆ๋‹ค. ์ด ํด๋”๊ฐ€ ์—†์œผ๋ฉด 30DaysOfPython์ด๋ผ๋Š” ํด๋” ์ด๋ฆ„์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ์ด ํด๋” ์•ˆ์— helloworld.py๋ผ๋Š” ํŒŒ์ผ์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ์ด์ œ Visual Studio ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Python ๋Œ€ํ™”ํ˜• ์…ธ์—์„œ ์ˆ˜ํ–‰ํ•œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +Python ๋Œ€ํ™”ํ˜• ์…ธ์€ **print**๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์ธ์‡„ํ–ˆ์ง€๋งŒ Visual Studio ์ฝ”๋“œ์—์„œ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ ค๋ฉด ๋‚ด์žฅ ํ•จ์ˆ˜ *print()๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. *print()* ๋‚ด์žฅ ํ•จ์ˆ˜๋Š” *print('arument1', 'argument2', 'argument3')*์™€ ๊ฐ™์ด ํ•˜๋‚˜ ์ด์ƒ์˜ ์ธ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ์˜ˆ๋ฅผ ์ฐธ์กฐํ•˜์‹ญ์‹œ์˜ค. + +**Example:** + +ํŒŒ์ผ ์ด๋ฆ„์€ helloworld.py. + +```py +# Day 1 - 30DaysOfPython Challenge + +print(2 + 3) # addition(+) +print(3 - 1) # subtraction(-) +print(2 * 3) # multiplication(*) +print(3 / 2) # division(/) +print(3 ** 2) # exponential(**) +print(3 % 2) # modulus(%) +print(3 // 2) # Floor division operator(//) + +# Checking data types +print(type(10)) # Int +print(type(3.14)) # Float +print(type(1 + 3j)) # Complex number +print(type('Asabeneh')) # String +print(type([1, 2, 3])) # List +print(type({'name':'Asabeneh'})) # Dictionary +print(type({9.8, 3.14, 2.7})) # Set +print(type((9.8, 3.14, 2.7))) # Tuple +``` + +Python ํŒŒ์ผ์„ ์‹คํ–‰ํ•˜๋ ค๋ฉด ์•„๋ž˜ ์ด๋ฏธ์ง€๋ฅผ ํ™•์ธํ•˜์„ธ์š”. Visual Studio Code์—์„œ ๋…น์ƒ‰ ๋ฒ„ํŠผ์„ ์‹คํ–‰ํ•˜๊ฑฐ๋‚˜ ํ„ฐ๋ฏธ๋„์— *python helloworld.py*๋ฅผ ์ž…๋ ฅํ•˜์—ฌ Python ํŒŒ์ผ์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +![Running python script](./images/running_python_script.png) + +๐ŸŒ• ์ข‹์Šต๋‹ˆ๋‹ค. ๋‹น์‹ ์€ ๋ฐฉ๊ธˆ 1์ผ์ฐจ ๋„์ „์„ ์™„๋ฃŒํ–ˆ๊ณ  ๋‹น์‹ ์€ ์œ„๋Œ€ํ•œ ์—ฌ์ •์— ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ ๋‡Œ์™€ ๊ทผ์œก์„ ์œ„ํ•œ ๋ช‡ ๊ฐ€์ง€ ํ›ˆ๋ จ์„ ํ•ด๋ด…์‹œ๋‹ค. + +## ๐Ÿ’ป Exercises - Day 1 + +### Exercise: Level 1 + +1. ์‚ฌ์šฉ ์ค‘์ธ Python ๋ฒ„์ „ ํ™•์ธ +2. Python ๋Œ€ํ™”ํ˜• ์…ธ์„ ์—ด๊ณ  ๋‹ค์Œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ํ”ผ์—ฐ์‚ฐ์ž๋Š” 3๊ณผ 4์ž…๋‹ˆ๋‹ค. + - ๋”ํ•˜๊ธฐ(+) + - ๋นผ๊ธฐ(-) + - ๊ณฑํ•˜๊ธฐ(\*) + - ๋‚˜๋จธ์ง€(%) + - ๋‚˜๋ˆ„๊ธฐ(/) + - ์ง€์ˆ˜(\*\*) + - ์ •์ˆ˜ ๋‚˜๋ˆ„๊ธฐ(//) +3. Python ๋Œ€ํ™”ํ˜• ์…ธ์— ๋ฌธ์ž์—ด์„ ์”๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค: + - ์ด๋ฆ„ + - ๊ฐ€์กฑ ์ด๋ฆ„ + - ๊ตญ๊ฐ€ ์ด๋ฆ„ + - I am enjoying 30 days of python +4. ๋‹ค์Œ ๋ฐ์ดํ„ฐ์˜ ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ํ™•์ธํ•˜์‹ญ์‹œ์˜ค.: + - 10 + - 9.8 + - 3.14 + - 4 - 4j + - ['Asabeneh', 'Python', 'Finland'] + - ์ด๋ฆ„ + - ๊ฐ€์กฑ ์ด๋ฆ„ + - ๊ตญ๊ฐ€ ์ด๋ฆ„ + +### Exercise: Level 2 + +1. 30DaysOfPython ํด๋” ์•ˆ์— day_1์ด๋ผ๋Š” ํด๋”๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. day_1 ํด๋” ์•ˆ์— python ํŒŒ์ผ helloworld.py๋ฅผ ๋งŒ๋“ค๊ณ  ์งˆ๋ฌธ 1, 2, 3, 4๋ฅผ ๋ฐ˜๋ณตํ•˜์„ธ์š”. Python ํŒŒ์ผ์—์„œ ์ž‘์—…ํ•  ๋•Œ _print()_๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ์žŠ์ง€ ๋งˆ์„ธ์š”. ํŒŒ์ผ์„ ์ €์žฅํ•œ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™ํ•˜์—ฌ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. + +### Exercise: Level 3 + +1. Number(Integer, Float, Complex), String, Boolean, List, Tuple, Set ๋ฐ Dictionary์™€ ๊ฐ™์€ ๋‹ค์–‘ํ•œ Python ๋ฐ์ดํ„ฐ ์œ ํ˜•์— ๋Œ€ํ•œ ์˜ˆ์ œ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. +2. ์ฐธ๊ณ  [Euclidian distance](https://en.wikipedia.org/wiki/Euclidean_distance#:~:text=In%20mathematics%2C%20the%20Euclidean%20distance,being%20called%20the%20Pythagorean%20distance.) (2, 3) ๊ณผ (10, 8) ์‚ฌ์ด + +๐ŸŽ‰ ์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค ! ๐ŸŽ‰ + +[Day 2 >>](./02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) \ No newline at end of file From 5051d4916aa90c2afad4b8ed6aad73474a5b3342 Mon Sep 17 00:00:00 2001 From: ShinYooJung Date: Wed, 7 Dec 2022 17:28:02 +0900 Subject: [PATCH 02/21] Add Day 2 Korean Translation --- .../02_variables_builtin_functions.md | 317 ++++++++++++++++++ 1 file changed, 317 insertions(+) create mode 100644 Korean/02_Day_Variables_builtin_functions/02_variables_builtin_functions.md diff --git a/Korean/02_Day_Variables_builtin_functions/02_variables_builtin_functions.md b/Korean/02_Day_Variables_builtin_functions/02_variables_builtin_functions.md new file mode 100644 index 00000000..0e8506b2 --- /dev/null +++ b/Korean/02_Day_Variables_builtin_functions/02_variables_builtin_functions.md @@ -0,0 +1,317 @@ +
+

30 Days Of Python: Day 2 - ๋ณ€์ˆ˜, ๋‚ด์žฅ ํ•จ์ˆ˜

+ + + + + Twitter Follow + + +Author: +Asabeneh Yetayeh
+ Second Edition: July, 2021 +
+ +
+ +[<< Day 1](../readme.md) | [Day 3 >>](../03_Day_Operators/03_operators.md) + +![30DaysOfPython](../../images/30DaysOfPython_banner3@2x.png) + +- [๐Ÿ“˜ Day 2](#-day-2) + - [๋‚ด์žฅ ํ•จ์ˆ˜](#๋‚ด์žฅ-ํ•จ์ˆ˜) + - [๋ณ€์ˆ˜](#๋ณ€์ˆ˜) + - [ํ•œ ์ค„๋กœ ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ณ€์ˆ˜ ์„ ์–ธ](#ํ•œ-์ค„๋กœ-์—ฌ๋Ÿฌ๊ฐœ์˜-๋ณ€์ˆ˜-์„ ์–ธ) + - [์ž๋ฃŒํ˜•](#์ž๋ฃŒํ˜•) + - [์ž๋ฃŒํ˜• ํ™•์ธ ๋ฐ ํ˜•๋ณ€ํ™˜](#์ž๋ฃŒํ˜•-ํ™•์ธ-๋ฐ-ํ˜•๋ณ€ํ™˜) + - [์ˆซ์ž](#์ˆซ์ž) + - [๐Ÿ’ป Exercises - Day 2](#-exercises---day-2) + - [Exercises: Level 1](#exercises-level-1) + - [Exercises: Level 2](#exercises-level-2) + +# ๐Ÿ“˜ Day 2 + +## ๋‚ด์žฅ ํ•จ์ˆ˜ + +ํŒŒ์ด์ฌ์—๋Š” ์ˆ˜๋งŽ์€ ๋‚ด์žฅ ํ•จ์ˆ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‚ด์žฅ ํ•จ์ˆ˜๋Š” ์ „์—ญ์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๊ณ  ๊ทธ๊ฑด importing ์ด๋‚˜ configuring์—†์ด ๋‚ด์žฅ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ๋œป์ž…๋‹ˆ๋‹ค. ๋‹ค์Œ์€ ๊ฐ€์žฅ ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ํŒŒ์ด์ฌ ๋‚ด์žฅํ•จ์ˆ˜๋“ค ์ค‘ ๋ช‡๊ฐ€์ง€์ž…๋‹ˆ๋‹ค: _print()_, _len()_, _type()_, _int()_, _float()_, _str()_, _input()_, _list()_, _dict()_, _min()_, _max()_, _sum()_, _sorted()_, _open()_, _file()_, _help()_, and _dir()_. ๋ฐ‘์˜ ํ‘œ์—์„œ [ํŒŒ์ด์ฌ ๊ณต์‹๋ฌธ์„œ](https://docs.python.org/3.9/library/functions.html) ์— ์“ฐ์—ฌ์ง„ ํŒŒ์ด์ฌ ๋‚ด์žฅ ํ•จ์ˆ˜์˜ ์ „์ฒด ๋ชฉ๋ก์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +![Built-in Functions](../../images/builtin-functions.png) + +ํŒŒ์ด์ฌ ์‰˜์„ ์—ด๊ณ  ๊ฐ€์žฅ ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ๋‚ด์žฅ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด๋ด…์‹œ๋‹ค. + +![Built-in functions](../../images/builtin-functions_practice.png) + +๋‹ค๋ฅธ ๋‚ด์žฅ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ๋” ์—ฐ์Šตํ•ด๋ด…์‹œ๋‹ค. + +![Help and Dir Built in Functions](../../images/help_and_dir_builtin.png) + +์œ„์˜ ํ„ฐ๋ฏธ๋„์—์„œ ๋ณผ ์ˆ˜ ์žˆ๋“ฏ์ด, ํŒŒ์ด์ฌ์—๋Š” reserved word๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. reserved word๋Š” ๋ณ€์ˆ˜๋‚˜ ํ•จ์ˆ˜๋ฅผ ์„ ์–ธํ• ๋•Œ ์‚ฌ์šฉ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋ณ€์ˆ˜์— ๊ด€ํ•ด์„œ๋Š” ๋‹ค์Œ ์žฅ์—์„œ ๋‹ค๋ฃฐ๊ฒƒ์ž…๋‹ˆ๋‹ค. + +์ด์ œ ๋‹น์‹ ์€ ๋‚ด์žฅ ํ•จ์ˆ˜์— ์ต์ˆ™ํ•ด์กŒ์„ ๊ฒƒ์ด๋ผ ๋ฏฟ์Šต๋‹ˆ๋‹ค. ํ•œ๋ฒˆ ๋” ๋‚ด์žฅ ํ•จ์ˆ˜์˜ ์—ฐ์Šต์„ ํ•˜๊ณ  ๋‹ค์Œ ์žฅ์œผ๋กœ ๋„˜์–ด๊ฐ‘์‹œ๋‹ค. +![Min Max Sum](../../images/builtin-functional-final.png) + +## ๋ณ€์ˆ˜ + +๋ณ€์ˆ˜๋Š” ์ปดํ“จํ„ฐ ๋ฉ”๋ชจ๋ฆฌ์— ์ •๋ณด๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. Mnemonic ๋ณ€์ˆ˜๋Š” ๋งŽ์€ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์—์„œ ์‚ฌ์šฉํ•˜๋„๋ก ๊ถŒ์žฅ๋ฉ๋‹ˆ๋‹ค. Mnemonic ๋ณ€์ˆ˜๋Š” ์‰ฝ๊ฒŒ ๊ธฐ์–ตํ•˜๊ณ  ์—ฐ๊ด€์ง€์„ ์ˆ˜ ์žˆ๋Š” ๋ณ€์ˆ˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค. ํ•œ ๋ณ€์ˆ˜๋Š” ์ •๋ณด๊ฐ€ ์ €์žฅ๋˜์–ด์žˆ๋Š” ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ๋ฅผ ์ฐธ์กฐํ•ฉ๋‹ˆ๋‹ค. +๋ณ€์ˆ˜ ์ด๋ฆ„์„ ์ง€์ •ํ•  ๋•Œ๋Š” ์‹œ์ž‘ ๋ถ€๋ถ„์˜ ์ˆซ์ž, ํŠน์ˆ˜ ๋ฌธ์ž, ํ•˜์ดํ”ˆ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋ณ€์ˆ˜๋Š” ์งง์€ ์ด๋ฆ„(์˜ˆ: x, y, z)์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์ง€๋งŒ ๋” ๋ณ€์ˆ˜์— ๋Œ€ํ•œ ์„ค๋ช…์„ ๋‹ด์€ ์ด๋ฆ„(์ด๋ฆ„, ์„ฑ, ๋‚˜์ด, ๊ตญ๊ฐ€)์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•ฉ๋‹ˆ๋‹ค. + +ํŒŒ์ด์ฌ ๋ณ€์ˆ˜ ์ด๋ฆ„ ๊ทœ์น™ + +- ๋ณ€์ˆ˜ ์ด๋ฆ„์€ ๋ฌธ์ž ๋˜๋Š” ๋ฐ‘์ค„ ๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค +- ๋ณ€์ˆ˜ ์ด๋ฆ„์€ ์ˆซ์ž๋กœ ์‹œ์ž‘ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค +- ๋ณ€์ˆ˜ ์ด๋ฆ„์—๋Š” ์•ŒํŒŒ๋ฒณ๊ณผ ์ˆซ์ž์™€ ๋ฐ‘์ค„(A-z, 0-9 ๋ฐ \_)๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค +- ๋ณ€์ˆ˜ ์ด๋ฆ„์€ ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•ฉ๋‹ˆ๋‹ค(firstname, Firstname, FirstName, FIRSTNAME์€ ์„œ๋กœ ๋‹ค๋ฅธ ๋ณ€์ˆ˜) + +์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ ๋ณ€์ˆ˜ ์ด๋ฆ„๋“ค์„ ์‚ดํŽด๋ด…์‹œ๋‹ค + +```shell +firstname +lastname +age +country +city +first_name +last_name +capital_city +_if # reserved word๋ฅผ ๋ณ€์ˆ˜ ์ด๋ฆ„์œผ๋กœ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ +year_2021 +year2021 +current_year_2021 +birth_year +num1 +num2 +``` + +์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š” ๋ณ€์ˆ˜ ์ด๋ฆ„๋“ค + +```shell +first-name +first@name +first$name +num-1 +1num +``` + +์šฐ๋ฆฌ๋Š” ๋งŽ์€ ํŒŒ์ด์ฌ ๊ฐœ๋ฐœ์ž๋“ค์ด ์ฑ„ํƒํ•œ ํ‘œ์ค€ ํŒŒ์ด์ฌ ๋ณ€์ˆ˜ ๋ช…๋ช… ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ํŒŒ์ด์ฌ ๊ฐœ๋ฐœ์ž๋“ค์€ ์Šค๋„ค์ดํฌ ์ผ€์ด์Šค(snake_case) ๋ณ€์ˆ˜ ๋ช…๋ช… ๊ทœ์น™์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๋Š” ๋‘ ๊ฐœ ์ด์ƒ์˜ ๋‹จ์–ด๋ฅผ ํฌํ•จํ•˜๋Š” ๋ณ€์ˆ˜์— ๋Œ€ํ•ด ๊ฐ ๋‹จ์–ด ๋’ค์— ๋ฐ‘์ค„ ๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค(์˜ˆ: first_name, last_name, engine_rotation_speed). ์•„๋ž˜ ์˜ˆ์ œ๋Š” ๋ณ€์ˆ˜์˜ ํ‘œ์ค€ ๋ช…๋ช… ์˜ˆ์ œ์ด๋ฉฐ, ๋ณ€์ˆ˜ ์ด๋ฆ„์ด ๋‘˜ ์ด์ƒ์˜ ๋‹จ์–ด์ผ ๊ฒฝ์šฐ ๋ฐ‘์ค„์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. + +๋ณ€์ˆ˜์— ํŠน์ • ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ํ• ๋‹นํ•  ๋•Œ ์ด๋ฅผ ๋ณ€์ˆ˜ ์„ ์–ธ์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์•„๋ž˜ ์˜ˆ์ œ์—์„œ ๋‚ด ์ด๋ฆ„์€ first_name ๋ณ€์ˆ˜์— ํ• ๋‹น๋ฉ๋‹ˆ๋‹ค. ๋“ฑํ˜ธ ๊ธฐํ˜ธ๋Š” ํ• ๋‹น ์—ฐ์‚ฐ์ž์ž…๋‹ˆ๋‹ค. ํ• ๋‹น์€ ๋ณ€์ˆ˜์— ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ํŒŒ์ด์ฌ์—์„œ ๋“ฑํ˜ธ ๊ธฐํ˜ธ๋Š” ์ˆ˜ํ•™์—์„œ์˜ ๋“ฑํ˜ธ๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค. + +_Example:_ + +```py +# Variables in Python +first_name = 'Asabeneh' +last_name = 'Yetayeh' +country = 'Finland' +city = 'Helsinki' +age = 250 +is_married = True +skills = ['HTML', 'CSS', 'JS', 'React', 'Python'] +person_info = { + 'firstname':'Asabeneh', + 'lastname':'Yetayeh', + 'country':'Finland', + 'city':'Helsinki' + } +``` + +๋‚ด์žฅ ํ•จ์ˆ˜์ธ _print()_ ์™€ _len()_ ์„ ์‚ฌ์šฉํ•ด๋ด…์‹œ๋‹ค. Print ํ•จ์ˆ˜๋Š” ์ธ์ž์˜ ์ˆ˜์— ์ œํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค. ์ธ์ž๋Š” ํ•จ์ˆ˜ ๊ด„ํ˜ธ ์•ˆ์— ๋„ฃ์–ด ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ’์ž…๋‹ˆ๋‹ค. ์•„๋ž˜ ์˜ˆ์ œ๋ฅผ ๋ด…์‹œ๋‹ค. + +**Example:** + +```py +print('Hello, World!') # Hello, World! ๋ผ๋Š” ๊ธ€์ด ํ•˜๋‚˜์˜ ์ธ์ž์ž…๋‹ˆ๋‹ค +print('Hello',',', 'World','!') # ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ธ์ž๋ฅผ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค, ๋„ค๊ฐœ์˜ ์ธ์ž๊ฐ€ ๋„˜๊ฒจ์กŒ์Šต๋‹ˆ๋‹ค +print(len('Hello, World!')) # ํ•˜๋‚˜์˜ ์ธ์ž๋งŒ์„ ๋ฐ›์Šต๋‹ˆ๋‹ค +``` + +์œ„์—์„œ ์ •์˜๋œ ๋ณ€์ˆ˜๋“ค์„ ์ฐ์–ด๋ณด๊ณ  ๊ธธ์ด๋ฅผ ์ฐพ์•„๋ด…์‹œ๋‹ค: + +**Example:** + +```py +# ๋ณ€์ˆ˜์— ์ €์žฅ๋œ ๊ฐ’ ์ฐ๊ธฐ + +print('First name:', first_name) +print('First name length:', len(first_name)) +print('Last name: ', last_name) +print('Last name length: ', len(last_name)) +print('Country: ', country) +print('City: ', city) +print('Age: ', age) +print('Married: ', is_married) +print('Skills: ', skills) +print('Person information: ', person_info) +``` + +### ํ•œ ์ค„๋กœ ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ณ€์ˆ˜ ์„ ์–ธ + +ํ•˜๋‚˜์˜ ์ค„์—์„œ ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค: + +**Example:** + +```py +first_name, last_name, country, age, is_married = 'Asabeneh', 'Yetayeh', 'Helsink', 250, True + +print(first_name, last_name, country, age, is_married) +print('First name:', first_name) +print('Last name: ', last_name) +print('Country: ', country) +print('Age: ', age) +print('Married: ', is_married) +``` + +๋‚ด์žฅ ํ•จ์ˆ˜ _input()_ ์„ ์‚ฌ์šฉํ•ด ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ. ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ๋ฐ›์€ ์ •๋ณด๋ฅผ first_name๊ณผ age ๋ณ€์ˆ˜์— ํ• ๋‹นํ•ด๋ด…์‹œ๋‹ค. +**Example:** + +```py +first_name = input('What is your name: ') +age = input('How old are you? ') + +print(first_name) +print(age) +``` + +## ์ž๋ฃŒํ˜• + +ํŒŒ์ด์ฌ์—๋Š” ๋ช‡ ๊ฐ€์ง€ ์ž๋ฃŒํ˜•์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ž๋ฃŒํ˜•์„ ์‹๋ณ„ํ•˜๊ธฐ ์œ„ํ•ด ๋‚ด์žฅ ํ•จ์ˆ˜ _type()_ ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์„œ๋กœ ๋‹ค๋ฅธ ์ž๋ฃŒํ˜•์„ ์ž˜ ์ดํ•ดํ•˜๋Š” ๋ฐ ์ง‘์ค‘ํ•ด ์ฃผ์‹œ๊ธฐ๋ฅผ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ๋ชจ๋“ ๊ฒƒ์€ ์ž๋ฃŒํ˜•๊ณผ ๊ด€๋ จ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ฒ˜์Œ์— ์ž๋ฃŒํ˜•์„ ์†Œ๊ฐœํ–ˆ์ง€๋งŒ ๋ชจ๋“  ์ฃผ์ œ๊ฐ€ ์ž๋ฃŒํ˜•๊ณผ ๊ด€๋ จ์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค์‹œ ๋‚˜์˜ต๋‹ˆ๋‹ค. ์ž๋ฃŒํ˜•์— ๋Œ€ํ•ด์„œ๋Š” ๊ฐ ์„น์…˜์—์„œ ์ž์„ธํžˆ ์„ค๋ช…ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +## ์ž๋ฃŒํ˜• ํ™•์ธ ๋ฐ ํ˜•๋ณ€ํ™˜ + +- ์ž๋ฃŒํ˜• ํ™•์ธ: ํŠน์ • ์ •๋ณด/๋ณ€์ˆ˜์˜ ์ž๋ฃŒํ˜•์„ ํ™•์ธํ•˜๊ธฐ์œ„ํ•ด ์šฐ๋ฆฌ๋Š” _type()_ ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค + **Example:** + +```py +# ๋‹ค์–‘ํ•œ ํŒŒ์ด์ฌ ์ž๋ฃŒํ˜• +# ๋‹ค์–‘ํ•œ ์ž๋ฃŒํ˜•์˜ ๋ณ€์ˆ˜๋“ค์„ ์„ ์–ธํ•ด ๋ด…์‹œ๋‹ค. + +first_name = 'Asabeneh' # str +last_name = 'Yetayeh' # str +country = 'Finland' # str +city= 'Helsinki' # str +age = 250 # int, ์ œ ์‹ค์ œ ๋‚˜์ด๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค, ๊ฑฑ์ •๋งˆ์„ธ์š” + +# Printing out types +print(type('Asabeneh')) # str +print(type(first_name)) # str +print(type(10)) # int +print(type(3.14)) # float +print(type(1 + 1j)) # complex +print(type(True)) # bool +print(type([1, 2, 3, 4])) # list +print(type({'name':'Asabeneh','age':250, 'is_married':250})) # dict +print(type((1,2))) # tuple +print(type(zip([1,2],[3,4]))) # set +``` + +- ํ˜•๋ณ€ํ™˜: ํ•˜๋‚˜์˜ ์ž๋ฃŒํ˜•์„ ๋‹ค๋ฅธ ์ž๋ฃŒํ˜•์œผ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค. _int()_, _float()_, _str()_, _list_, _set_ ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + ์‚ฐ์ˆ  ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰ํ•  ๋•Œ ๋ฌธ์ž์—ด ์ˆซ์ž๋“ค์„ ๋จผ์ € int ๋‚˜ float๋กœ ๋ณ€ํ™˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋ฐ˜ํ™˜๋ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์ˆซ์ž๋ฅผ ๋ฌธ์ž์—ด๊ณผ ๊ฒฐํ•ฉํ•œ๋‹ค๋ฉด, ๊ทธ ์ˆซ์ž๋Š” ๋จผ์ € ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ฒฐํ•ฉ์— ๋Œ€ํ•ด์„œ๋Š” String ์„น์…˜์—์„œ ์„ค๋ช…ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + + **Example:** + +```py +# int to float +num_int = 10 +print('num_int',num_int) # 10 +num_float = float(num_int) +print('num_float:', num_float) # 10.0 + +# float to int +gravity = 9.81 +print(int(gravity)) # 9 + +# int to str +num_int = 10 +print(num_int) # 10 +num_str = str(num_int) +print(num_str) # '10' + +# str to int or float +num_str = '10.6' +print('num_int', int(num_str)) # 10 +print('num_float', float(num_str)) # 10.6 + +# str to list +first_name = 'Asabeneh' +print(first_name) # 'Asabeneh' +first_name_to_list = list(first_name) +print(first_name_to_list) # ['A', 's', 'a', 'b', 'e', 'n', 'e', 'h'] +``` + +## ์ˆซ์ž + +ํŒŒ์ด์ฌ์˜ ์ˆซ์ž ์ž๋ฃŒํ˜•: + +1. Integers: ์ •์ˆ˜(์Œ์ˆ˜, 0 , ์–‘์ˆ˜) + ์˜ˆ: + ... -3, -2, -1, 0, 1, 2, 3 ... + +2. ๋ถ€๋™ ์†Œ์ˆ˜์  ์ˆซ์ž(10์ง„์ˆ˜) + ์˜ˆ: + ... -3.5, -2.25, -1.0, 0.0, 1.1, 2.2, 3.5 ... + +3. ๋ณต์†Œ์ˆ˜ + ์˜ˆ: + 1 + j, 2 + 4j, 1 - 1j + +๐ŸŒ• ๋‹น์‹ ์€ ์ •๋ง ๋ฉ‹์ง‘๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ๋ถ„์€ ์ด์ œ ๋ง‰ 2์ผ์ฐจ ๋„์ „์„ ๋งˆ์ณค๊ณ  ์œ„๋Œ€ํ•จ์œผ๋กœ ๊ฐ€๋Š” ๊ธธ์— ๋‘ ๊ฑธ์Œ ์•ž์„œ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ ์—ฌ๋Ÿฌ๋ถ„์˜ ๋‡Œ์™€ ๊ทผ์œก์„ ์œ„ํ•œ ์šด๋™์„ ํ•˜์„ธ์š”. + +## ๐Ÿ’ป Exercises - Day 2 + +### Exercises: Level 1 + +1. 30DaysOfPython ๋‚ด์— day_2๋ผ๋Š” ํด๋”๋ฅผ ์ƒ์„ฑํ•˜์„ธ์š”. ๊ทธ ํด๋” ๋‚ด์— variables.py ๋ผ๋Š” ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜์„ธ์š”. +2. 'Day 2: 30 Days of python programming'์ด๋ผ๋Š” ํŒŒ์ด์ฌ ์ฃผ์„์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. +3. first name ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ๋ณ€์ˆ˜์— ๊ฐ’์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. +4. last name ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ๋ณ€์ˆ˜์— ๊ฐ’์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. +5. full name ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ๋ณ€์ˆ˜์— ๊ฐ’์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. +6. country ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ๊ฐ’์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. +7. city ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ๊ฐ’์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. +8. age ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ๊ฐ’์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. +9. year ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ๊ฐ’์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. +10. is_married ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ๊ฐ’์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. +11. is_true ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ๊ฐ’์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. +12. is_light_on ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ๊ฐ’์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. +13. ํ•œ ์ค„์— ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค. + +### Exercises: Level 2 + +1. Check the data type of all your variables using type() built-in function +1. Using the _len()_ built-in function, find the length of your first name +1. Compare the length of your first name and your last name +1. Declare 5 as num_one and 4 as num_two + 1. Add num_one and num_two and assign the value to a variable total + 2. Subtract num_two from num_one and assign the value to a variable diff + 3. Multiply num_two and num_one and assign the value to a variable product + 4. Divide num_one by num_two and assign the value to a variable division + 5. Use modulus division to find num_two divided by num_one and assign the value to a variable remainder + 6. Calculate num_one to the power of num_two and assign the value to a variable exp + 7. Find floor division of num_one by num_two and assign the value to a variable floor_division +1. The radius of a circle is 30 meters. + 1. Calculate the area of a circle and assign the value to a variable name of _area_of_circle_ + 2. Calculate the circumference of a circle and assign the value to a variable name of _circum_of_circle_ + 3. Take radius as user input and calculate the area. +1. Use the built-in input function to get first name, last name, country and age from a user and store the value to their corresponding variable names +1. Run help('keywords') in Python shell or in your file to check for the Python reserved words or keywords + +1. type() ๋‚ด์žฅ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋“  ๋ณ€์ˆ˜์˜ ์ž๋ฃŒํ˜•์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. +1. _len()_ ๋‚ด์žฅ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹น์‹ ์˜ first name ์˜ ๊ธธ์ด๋ฅผ ์ฐพ์Šต๋‹ˆ๋‹ค. +1. ๋‹น์‹ ์˜ first name ๊ณผ last name ์˜ ๊ธธ์ด๋ฅผ ๋น„๊ตํ•ฉ๋‹ˆ๋‹ค. +1. 5๋ฅผ num_1๋กœ, 4๋ฅผ num_2๋กœ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค. + 1. num_one๊ณผ num_two๋ฅผ ๋”ํ•˜๊ณ  ๊ทธ ๊ฐ’์„ ๋ณ€์ˆ˜ total ์— ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. + 2. num_1์—์„œ num_2๋ฅผ ๋นผ๊ณ  ๊ทธ ๊ฐ’์„ ๋ณ€์ˆ˜ diff ์— ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. + 3. num_two์™€ num_one์„ ๊ณฑํ•˜์—ฌ ๊ทธ ๊ฐ’์„ ๋ณ€์ˆ˜ product ์— ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. + 4. num_one์„ num_two๋กœ ๋‚˜๋ˆ„๊ณ  ๊ทธ ๊ฐ’์„ ๋ณ€์ˆ˜ division ์— ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. + 5. ๋‚˜๋จธ์ง€ ์—ฐ์‚ฐ์„ ์‚ฌ์šฉํ•˜์—ฌ num_two๋ฅผ num_one์œผ๋กœ ๋‚˜๋ˆˆ ๊ฐ’์„ ์ฐพ๊ณ  ๋ณ€์ˆ˜ remainder ์— ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. + 6. num_one์„ num_two์˜ ๊ฑฐ๋“ญ์ œ๊ณฑ์œผ๋กœ ๊ณ„์‚ฐํ•˜๊ณ  ๊ทธ ๊ฐ’์„ ๋ณ€์ˆ˜ exp ์— ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. + 7. num_one์„ num_two๋กœ ๋‚˜๋ˆ„๊ณ  ์†Œ์ˆซ๊ฐ’์€ ๋ฒ„๋ฆฐ ์ •์ˆ˜ ๊ฐ’์„ ๊ตฌํ•˜๊ณ  ๋ณ€์ˆ˜ floor_division ์— ๊ฐ’์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. +1. ์›์˜ ๋ฐ˜์ง€๋ฆ„์€ 30๋ฏธํ„ฐ์ž…๋‹ˆ๋‹ค. + 1. ์›์˜ ๋ฉด์ ์„ ๊ณ„์‚ฐํ•˜์—ฌ _area_of_circle_ ์ด๋ผ๋Š” ์ด๋ฆ„์˜ ๋ณ€์ˆ˜์— ๊ฐ’์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. + 2. ์›์˜ ๋‘˜๋ ˆ๋ฅผ ๊ณ„์‚ฐํ•˜์—ฌ _circum_of_circum_ ์ด๋ผ๋Š” ์ด๋ฆ„์˜ ๋ณ€์ˆ˜์— ๊ฐ’์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. + 3. ๋ฐ˜๊ฒฝ์„ ์‚ฌ์šฉ์ž ์ž…๋ ฅ์œผ๋กœ ๋ฐ›์•„์„œ ๋ฉด์ ์„ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค. +1. ๋‚ด์žฅ ํ•จ์ˆ˜ input์„ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ด๋ฆ„, ์„ฑ, ๊ตญ๊ฐ€ ๋ฐ ๋‚˜์ด๋ฅผ ์–ป๊ณ  ํ•ด๋‹น ๋ณ€์ˆ˜ ์ด๋ฆ„์— ๊ฐ’์„ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. +1. Python ์…ธ ๋˜๋Š” ํŒŒ์ผ์—์„œ help('keywords')์„ ์‹คํ–‰ํ•˜์—ฌ ํŒŒ์ด์ฌ์˜ reserved words ๋˜๋Š” ํ‚ค์›Œ๋“œ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. + +๐ŸŽ‰ ์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค ! ๐ŸŽ‰ + +[<< Day 1](../readme.md) | [Day 3 >>](../03_Day_Operators/03_operators.md) From e708e3086d9eeebd81a3a2951b58c786d4af2117 Mon Sep 17 00:00:00 2001 From: kjs1019 <68845945+kjs1019@users.noreply.github.com> Date: Wed, 7 Dec 2022 19:36:46 +0900 Subject: [PATCH 03/21] Create korean --- korean | 1 + 1 file changed, 1 insertion(+) create mode 100644 korean diff --git a/korean b/korean new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/korean @@ -0,0 +1 @@ + From c1364a4a5ec8f1c8dc4819620ca68690ac6377d6 Mon Sep 17 00:00:00 2001 From: jshyun1 Date: Thu, 8 Dec 2022 13:13:09 +0900 Subject: [PATCH 04/21] lang ko --- lang-ko/readme_ko.md | 136 +++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/lang-ko/readme_ko.md b/lang-ko/readme_ko.md index 770ee592..558efe95 100644 --- a/lang-ko/readme_ko.md +++ b/lang-ko/readme_ko.md @@ -2,42 +2,42 @@ |# Day | Topics | |------|:---------------------------------------------------------:| -| 01 | [Introduction](./readme.md)| -| 02 | [Variables, Built-in Functions](./02_Day_Variables_builtin_functions/02_variables_builtin_functions.md)| -| 03 | [Operators](./03_Day_Operators/03_operators.md)| -| 04 | [Strings](./04_Day_Strings/04_strings.md)| -| 05 | [Lists](./05_Day_Lists/05_lists.md)| -| 06 | [Tuples](./06_Day_Tuples/06_tuples.md)| -| 07 | [Sets](./07_Day_Sets/07_sets.md)| -| 08 | [Dictionaries](./08_Day_Dictionaries/08_dictionaries.md)| -| 09 | [Conditionals](./09_Day_Conditionals/09_conditionals.md)| -| 10 | [Loops](./10_Day_Loops/10_loops.md)| -| 11 | [Functions](./11_Day_Functions/11_functions.md)| -| 12 | [Modules](./12_Day_Modules/12_modules.md)| -| 13 | [List Comprehension](./13_Day_List_comprehension/13_list_comprehension.md)| -| 14 | [Higher Order Functions](./14_Day_Higher_order_functions/14_higher_order_functions.md)| -| 15 | [Python Type Errors](./15_Day_Python_type_errors/15_python_type_errors.md)| -| 16 | [Python Date time](./16_Day_Python_date_time/16_python_datetime.md) | -| 17 | [Exception Handling](./17_Day_Exception_handling/17_exception_handling.md)| -| 18 | [Regular Expressions](./18_Day_Regular_expressions/18_regular_expressions.md)| -| 19 | [File Handling](./19_Day_File_handling/19_file_handling.md)| -| 20 | [Python Package Manager](./20_Day_Python_package_manager/20_python_package_manager.md)| -| 21 | [Classes and Objects](./21_Day_Classes_and_objects/21_classes_and_objects.md)| -| 22 | [Web Scraping](./22_Day_Web_scraping/22_web_scraping.md)| -| 23 | [Virtual Environment](./23_Day_Virtual_environment/23_virtual_environment.md)| -| 24 | [Statistics](./24_Day_Statistics/24_statistics.md)| -| 25 | [Pandas](./25_Day_Pandas/25_pandas.md)| -| 26 | [Python web](./26_Day_Python_web/26_python_web.md)| -| 27 | [Python with MongoDB](./27_Day_Python_with_mongodb/27_python_with_mongodb.md)| -| 28 | [API](./28_Day_API/28_API.md)| -| 29 | [Building API](./29_Day_Building_API/29_building_API.md)| -| 30 | [Conclusions](./30_Day_Conclusions/30_conclusions.md)| +| 01 | [Introduction](../readme_ko.md)| +| 02 | [Variables, Built-in Functions](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md)| +| 03 | [Operators](../03_Day_Operators/03_operators.md)| +| 04 | [Strings](../04_Day_Strings/04_strings.md)| +| 05 | [Lists](../05_Day_Lists/05_lists.md)| +| 06 | [Tuples](../06_Day_Tuples/06_tuples.md)| +| 07 | [Sets](../07_Day_Sets/07_sets.md)| +| 08 | [Dictionaries](../08_Day_Dictionaries/08_dictionaries.md)| +| 09 | [Conditionals](../09_Day_Conditionals/09_conditionals.md)| +| 10 | [Loops](../10_Day_Loops/10_loops.md)| +| 11 | [Functions](../11_Day_Functions/11_functions.md)| +| 12 | [Modules](../12_Day_Modules/12_modules.md)| +| 13 | [List Comprehension](../13_Day_List_comprehension/13_list_comprehension.md)| +| 14 | [Higher Order Functions](../14_Day_Higher_order_functions/14_higher_order_functions.md)| +| 15 | [Python Type Errors](../15_Day_Python_type_errors/15_python_type_errors.md)| +| 16 | [Python Date time](../16_Day_Python_date_time/16_python_datetime.md) | +| 17 | [Exception Handling](../17_Day_Exception_handling/17_exception_handling.md)| +| 18 | [Regular Expressions](../18_Day_Regular_expressions/18_regular_expressions.md)| +| 19 | [File Handling](../19_Day_File_handling/19_file_handling.md)| +| 20 | [Python Package Manager](../20_Day_Python_package_manager/20_python_package_manager.md)| +| 21 | [Classes and Objects](../21_Day_Classes_and_objects/21_classes_and_objects.md)| +| 22 | [Web Scraping](../22_Day_Web_scraping/22_web_scraping.md)| +| 23 | [Virtual Environment](../23_Day_Virtual_environment/23_virtual_environment.md)| +| 24 | [Statistics](../24_Day_Statistics/24_statistics.md)| +| 25 | [Pandas](../25_Day_Pandas/25_pandas.md)| +| 26 | [Python web](../26_Day_Python_web/26_python_web.md)| +| 27 | [Python with MongoDB](../27_Day_Python_with_mongodb/27_python_with_mongodb.md)| +| 28 | [API](../28_Day_API/28_API.md)| +| 29 | [Building API](../29_Day_Building_API/29_building_API.md)| +| 30 | [Conclusions](../30_Day_Conclusions/30_conclusions.md)| ๐Ÿงก๐Ÿงก๐Ÿงก HAPPY CODING ๐Ÿงก๐Ÿงก๐Ÿงก
Support the author to create more educational materials
-Paypal Logo +Paypal Logo
@@ -56,25 +56,25 @@
-[Day 2 >>](./02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) +[Day 2 >>](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) -![30DaysOfPython](./images/30DaysOfPython_banner3@2x.png) +![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png) - [๐Ÿ 30 Days Of Python](#-30-days-of-python) - [๐Ÿ“˜ Day 1](#-day-1) - - [ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค](#welcome) - - [์†Œ๊ฐœ](#introduction) - - [์™œ Python์ด๋Š๋ƒ?](#why-python-) - - [ํ™˜๊ฒฝ ์„ค์ •](#environment-setup) - - [Python ์„ค์น˜](#installing-python) - - [Python ์…ธ](#python-shell) - - [Visual Studio Code ์„ค์น˜](#installing-visual-studio-code) - - [visual studio code๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ](#how-to-use-visual-studio-code) - - [Python ๊ธฐ๋ณธ](#basic-python) - - [Python ๊ตฌ๋ฌธ](#python-syntax) - - [Python ๋“ค์—ฌ์“ฐ๊ธฐ](#python-indentation) - - [์ฃผ์„](#comments) - - [๋ฐ์ดํ„ฐ ํƒ€์ž…](#data-types) + - [ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค](#ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค) + - [์†Œ๊ฐœ](#์†Œ๊ฐœ) + - [์™œ Python์ด๋Š๋ƒ?](#์™œ-python์ด๋Š๋ƒ?) + - [ํ™˜๊ฒฝ ์„ค์ •](#ํ™˜๊ฒฝ-์„ค์ •) + - [Python ์„ค์น˜](#python-์„ค์น˜) + - [Python ์…ธ](#python-์…ธ) + - [Visual Studio Code ์„ค์น˜](#visual-studio-code-์„ค์น˜) + - [visual studio code๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ](#visual-studio-code๋ฅผ-์‚ฌ์šฉํ•˜๊ธฐ) + - [Python ๊ธฐ๋ณธ](#python-๊ธฐ๋ณธ) + - [Python ๊ตฌ๋ฌธ](#python-๊ตฌ๋ฌธ) + - [Python ๋“ค์—ฌ์“ฐ๊ธฐ](#python-๋“ค์—ฌ์“ฐ๊ธฐ) + - [์ฃผ์„](#์ฃผ์„) + - [๋ฐ์ดํ„ฐ ํƒ€์ž…](#๋ฐ์ดํ„ฐ-ํƒ€์ž…) - [Number](#number) - [String](#string) - [Booleans](#booleans) @@ -82,8 +82,8 @@ - [Dictionary](#dictionary) - [Tuple](#tuple) - [Set](#set) - - [๋ฐ์ดํ„ฐ ํƒ€์ž… ์ฒดํฌ](#checking-data-types) - - [Python ํŒŒ์ผ](#python-file) + - [๋ฐ์ดํ„ฐ ํƒ€์ž… ์ฒดํฌ](#๋ฐ์ดํ„ฐ-ํƒ€์ž…-์ฒดํฌ) + - [Python ํŒŒ์ผ](#python-ํŒŒ์ผ) - [๐Ÿ’ป Exercises - Day 1](#-exercises---day-1) - [Exercise: Level 1](#exercise-level-1) - [Exercise: Level 2](#exercise-level-2) @@ -119,7 +119,7 @@ Windows ์‚ฌ์šฉ์ž์ธ ๊ฒฝ์šฐ. ๋นจ๊ฐ„์ƒ‰ ๋™๊ทธ๋ผ๋ฏธ ์นœ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ macOS ์‚ฌ์šฉ์ž์ธ ๊ฒฝ์šฐ. ๋นจ๊ฐ„์ƒ‰ ๋™๊ทธ๋ผ๋ฏธ ์นœ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. -[![Windows์—์„œ ์„ค์น˜](./images/installing_on_windows.png)](https://www.python.org/) +[![Windows์—์„œ ์„ค์น˜](../images/installing_on_windows.png)](https://www.python.org/) Python์ด ์„ค์น˜๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋ ค๋ฉด ์žฅ์น˜ ํ„ฐ๋ฏธ๋„์— ๋‹ค์Œ ๋ช…๋ น์„ ์ž‘์„ฑํ•˜์‹ญ์‹œ์˜ค. @@ -127,7 +127,7 @@ Python์ด ์„ค์น˜๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋ ค๋ฉด ์žฅ์น˜ ํ„ฐ๋ฏธ๋„์— ๋‹ค์Œ ๋ช… python --version ``` -![Python Version](./images/python_versio.png) +![Python Version](../images/python_versio.png) ํ„ฐ๋ฏธ๋„์—์„œ ๋ณด์‹œ๋‹ค์‹œํ”ผ ์ €๋Š” ํ˜„์žฌ _Python 3.7.5_ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ท€ํ•˜์˜ Python ๋ฒ„์ „์€ ๋‚ด ๋ฒ„์ „๊ณผ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์ง€๋งŒ 3.6 ์ด์ƒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Python ๋ฒ„์ „์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค๋ฉด ์ž˜ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด์ œ ์ปดํ“จํ„ฐ์— Python์ด ์„ค์น˜๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ์„น์…˜์œผ๋กœ ๊ณ„์† ์ง„ํ–‰ํ•˜์‹ญ์‹œ์˜ค. @@ -142,35 +142,35 @@ Python Shell์€ ์‚ฌ์šฉ์ž์˜ Python ์ฝ”๋“œ๋ฅผ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค. ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅ python ``` -![Python Scripting Shell](./images/opening_python_shell.png) +![Python Scripting Shell](../images/opening_python_shell.png) Python ๋Œ€ํ™”ํ˜• ์…ธ์ด ์—ด๋ฆฌ๊ณ  Python ์ฝ”๋“œ(Python ์Šคํฌ๋ฆฝํŠธ)๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ๋ฅผ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค. ๊ธฐํ˜ธ >>> ์˜†์— Python ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  Enter๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค. Python ์Šคํฌ๋ฆฝํŒ… ์…ธ์—์„œ ์ฒซ ๋ฒˆ์งธ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. -![Python script on Python shell](./images/adding_on_python_shell.png) +![Python script on Python shell](../images/adding_on_python_shell.png) ํ›Œ๋ฅญํ•ฉ๋‹ˆ๋‹ค. Python ๋Œ€ํ™”ํ˜• ์…ธ์—์„œ ์ฒซ ๋ฒˆ์งธ Python ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. Python ๋Œ€ํ™”ํ˜• ์…ธ์„ ์–ด๋–ป๊ฒŒ ๋‹ซ์Šต๋‹ˆ๊นŒ? ์…ธ์„ ๋‹ซ์œผ๋ ค๋ฉด ๊ธฐํ˜ธ ์˜†์— >> **exit()** ๋ช…๋ น์„ ์ž‘์„ฑํ•˜๊ณ  Enter ํ‚ค๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค. -![Exit from python shell](./images/exit_from_shell.png) +![Exit from python shell](../images/exit_from_shell.png) ์ด์ œ Python ๋Œ€ํ™”ํ˜• ์…ธ์„ ์—ฌ๋Š” ๋ฐฉ๋ฒ•๊ณผ ์ข…๋ฃŒํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•˜์Šต๋‹ˆ๋‹ค. Python์€ Python์ด ์ดํ•ดํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ๊ฒฐ๊ณผ๋ฅผ ์ œ๊ณตํ•˜๊ณ  ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์˜ค๋ฅ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๊ณ ์˜์ ์ธ ์‹ค์ˆ˜๋ฅผ ํ•˜๊ณ  Python์ด ๋ฌด์—‡์„ ๋ฐ˜ํ™˜ํ•˜๋Š”์ง€ ๋ด…์‹œ๋‹ค. -![Invalid Syntax Error](./images/invalid_syntax_error.png) +![Invalid Syntax Error](../images/invalid_syntax_error.png) ๋ฐ˜ํ™˜๋œ ์˜ค๋ฅ˜์—์„œ ๋ณผ ์ˆ˜ ์žˆ๋“ฏ์ด Python์€ ์šฐ๋ฆฌ๊ฐ€ ์ €์ง€๋ฅธ ์‹ค์ˆ˜์™€ _Syntax Error: invalid syntax_๋ฅผ ์•Œ๊ณ  ์žˆ์„ ์ •๋„๋กœ ์˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค. Python์—์„œ x๋ฅผ ๊ณฑ์…ˆ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ (x)๊ฐ€ Python์—์„œ ์œ ํšจํ•œ ๊ตฌ๋ฌธ์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ตฌ๋ฌธ ์˜ค๋ฅ˜์ž…๋‹ˆ๋‹ค. (**x**) ๋Œ€์‹  ๊ณฑ์…ˆ์— ๋ณ„ํ‘œ(*)๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋ฐ˜ํ™˜๋œ ์˜ค๋ฅ˜๋Š” ์ˆ˜์ •ํ•ด์•ผ ํ•  ์‚ฌํ•ญ์„ ๋ช…ํ™•ํ•˜๊ฒŒ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. ํ”„๋กœ๊ทธ๋žจ์—์„œ ์˜ค๋ฅ˜๋ฅผ ์‹๋ณ„ํ•˜๊ณ  ์ œ๊ฑฐํ•˜๋Š” ํ”„๋กœ์„ธ์Šค๋ฅผ *๋””๋ฒ„๊น…*์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. **x** ๋Œ€์‹  *๋ฅผ ๋„ฃ์–ด ๋””๋ฒ„๊น…ํ•ด ๋ด…์‹œ๋‹ค. -![Fixing Syntax Error](./images/fixing_syntax_error.png) +![Fixing Syntax Error](../images/fixing_syntax_error.png) ๋ฒ„๊ทธ๊ฐ€ ์ˆ˜์ •๋˜์—ˆ๊ณ  ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋˜์—ˆ์œผ๋ฉฐ ์˜ˆ์ƒํ–ˆ๋˜ ๊ฒฐ๊ณผ๋ฅผ ์–ป์—ˆ์Šต๋‹ˆ๋‹ค. ํ”„๋กœ๊ทธ๋ž˜๋จธ๋กœ์„œ ๋งค์ผ ์ด๋Ÿฌํ•œ ์ข…๋ฅ˜์˜ ์˜ค๋ฅ˜๋ฅผ ๋ณด๊ฒŒ ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋””๋ฒ„๊น… ๋ฐฉ๋ฒ•์„ ์•„๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ๋””๋ฒ„๊น…์„ ์ž˜ํ•˜๋ ค๋ฉด ์–ด๋–ค ์ข…๋ฅ˜์˜ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ๋Š”์ง€ ์ดํ•ดํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” Python ์˜ค๋ฅ˜ ์ค‘ ์ผ๋ถ€๋Š” *SyntaxError*, *IndexError*, *NameError*, *ModuleNotFoundError*, *KeyError*, *ImportError*, *AttributeError*, *TypeError*, *ValueError*, *ZeroDivisionError* ๋“ฑ์ž…๋‹ˆ๋‹ค. ์ดํ›„ ์„น์…˜์—์„œ ๋‹ค๋ฅธ Python **_์˜ค๋ฅ˜ ์œ ํ˜•_**์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณผ ๊ฒƒ์ž…๋‹ˆ๋‹ค. Python ๋Œ€ํ™”ํ˜• ์…ธ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋” ์—ฐ์Šตํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ํ„ฐ๋ฏธ๋„์ด๋‚˜ ๋ช…๋ น ํ”„๋กฌํ”„ํŠธ๋กœ ์ด๋™ํ•˜์—ฌ **python**์ด๋ผ๋Š” ๋‹จ์–ด๋ฅผ ์”๋‹ˆ๋‹ค. -![Python Scripting Shell](./images/opening_python_shell.png) +![Python Scripting Shell](../images/opening_python_shell.png) Python ๋Œ€ํ™”ํ˜• ์…ธ์ด ์—ด๋ฆฝ๋‹ˆ๋‹ค. ๋ช‡ ๊ฐ€์ง€ ๊ธฐ๋ณธ์ ์ธ ์ˆ˜ํ•™ ์—ฐ์‚ฐ(๋”ํ•˜๊ธฐ, ๋นผ๊ธฐ, ๊ณฑํ•˜๊ธฐ, ๋‚˜๋ˆ„๊ธฐ, ๋‚˜๋จธ์ง€, ์ง€์ˆ˜)์„ ์ˆ˜ํ–‰ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. @@ -197,17 +197,17 @@ _comment_๋Š” Python์— ์˜ํ•ด ์‹คํ–‰๋˜์ง€ ์•Š๋Š” ์ฝ”๋“œ์˜ ์ผ๋ถ€์ž…๋‹ˆ๋‹ค. ๋”ฐ # (#) ์‹ฌ๋ณผ๋กœ ์‹œ์ž‘ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด๊ฒƒ์€ ํŒŒ์ด์ฌ ์ฃผ์„์ž…๋‹ˆ๋‹ค. ``` -![Maths on python shell](./images/maths_on_python_shell.png) +![Maths on python shell](../images/maths_on_python_shell.png) ๋‹ค์Œ ์„น์…˜์œผ๋กœ ์ด๋™ํ•˜๊ธฐ ์ „์— Python ๋Œ€ํ™”ํ˜• ์…ธ์—์„œ ๋” ๋งŽ์€ ์—ฐ์Šต์„ ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์…ธ์—์„œ _exit()_๋ฅผ ์ž‘์„ฑํ•˜์—ฌ ์—ด๋ฆฐ ์…ธ์„ ๋‹ซ์•˜๋‹ค๊ฐ€ ๋‹ค์‹œ ์—ด์–ด Python ์…ธ์—์„œ ํ…์ŠคํŠธ๋ฅผ ์“ฐ๋Š” ๋ฐฉ๋ฒ•์„ ์—ฐ์Šตํ•ด ๋ด…์‹œ๋‹ค. -![Writing String on python shell](./images/writing_string_on_shell.png) +![Writing String on python shell](../images/writing_string_on_shell.png) ### Visual Studio Code ์„ค์น˜ Python ๋Œ€ํ™”ํ˜• ์…ธ์€ ์ž‘์€ ์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋ฅผ ์‹œ๋„ํ•˜๊ณ  ํ…Œ์ŠคํŠธํ•˜๋Š” ๋ฐ ์ ํ•ฉํ•˜์ง€๋งŒ ํฐ ํ”„๋กœ์ ํŠธ์—๋Š” ์ ํ•ฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์‹ค์ œ ์ž‘์—… ํ™˜๊ฒฝ์—์„œ ๊ฐœ๋ฐœ์ž๋Š” ๋‹ค์–‘ํ•œ ์ฝ”๋“œ ํŽธ์ง‘๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ด 30์ผ๊ฐ„์˜ Python ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ฑŒ๋ฆฐ์ง€์—์„œ๋Š” Visual Studio ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Visual Studio Code๋Š” ๋งค์šฐ ์ธ๊ธฐ ์žˆ๋Š” ์˜คํ”ˆ ์†Œ์Šค ํ…์ŠคํŠธ ํŽธ์ง‘๊ธฐ์ž…๋‹ˆ๋‹ค. ๋‚˜๋Š” vscode์˜ ํŒฌ์ด๊ณ  Visual Studio ์ฝ”๋“œ๋ฅผ [๋‹ค์šด๋กœ๋“œ](https://code.visualstudio.com/)ํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•˜๊ณ  ์‹ถ์ง€๋งŒ, ๋‹ค๋ฅธ ํŽธ์ง‘์ž๋ฅผ ์„ ํ˜ธํ•œ๋‹ค๋ฉด ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒƒ์„ ์ž์œ ๋กญ๊ฒŒ ๋”ฐ๋ฅด์‹ญ์‹œ์˜ค. -[![Visual Studio Code](./images/vscode.png)](https://code.visualstudio.com/) +[![Visual Studio Code](../images/vscode.png)](https://code.visualstudio.com/) Visual Studio Code๋ฅผ ์„ค์น˜ํ•˜์…จ๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋น„๋””์˜ค๋ฅผ ์„ ํ˜ธํ•˜๋Š” ๊ฒฝ์šฐ Python์šฉ Visual Studio Code[๋น„๋””์˜ค ์ž์Šต์„œ](https://www.youtube.com/watch?v=bn7Cx4z-vSo)๋ฅผ ๋”ฐ๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. @@ -216,21 +216,21 @@ Visual Studio Code๋ฅผ ์„ค์น˜ํ•˜์…จ๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€ ์•Œ์•„๋ณด๊ฒ  Visual Studio ์•„์ด์ฝ˜์„ ๋‘ ๋ฒˆ ํด๋ฆญํ•˜์—ฌ Visual Studio ์ฝ”๋“œ๋ฅผ ์—ฝ๋‹ˆ๋‹ค. ์—ด๋ฉด ์ด๋Ÿฐ ์ข…๋ฅ˜์˜ ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค. ๋ ˆ์ด๋ธ”์ด ์ง€์ •๋œ ์•„์ด์ฝ˜์„ ๋”ฐ๋ผํ•ด๋ณด์„ธ์š”. -![Visual studio Code](./images/vscode_ui.png) +![Visual studio Code](../images/vscode_ui.png) ๋ฐ”ํƒ• ํ™”๋ฉด์— 30DaysOfPython์ด๋ผ๋Š” ํด๋”๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ Visual Studio ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ฝ์‹œ๋‹ค. -![Opening Project on Visual studio](./images/how_to_open_project_on_vscode.png) +![Opening Project on Visual studio](../images/how_to_open_project_on_vscode.png) -![Opening a project](./images/opening_project.png) +![Opening a project](../images/opening_project.png) ํŒŒ์ผ์„ ์—ด๋ฉด 30DaysOfPython ํ”„๋กœ์ ํŠธ์˜ ๋””๋ ‰ํ† ๋ฆฌ ๋‚ด๋ถ€์— ํŒŒ์ผ๊ณผ ํด๋”๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•œ ๋ฐ”๋กœ ๊ฐ€๊ธฐ๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์—์„œ ๋ณผ ์ˆ˜ ์žˆ๋“ฏ์ด ์ฒซ ๋ฒˆ์งธ ํŒŒ์ผ์ธ helloworld.py๋ฅผ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹น์‹ ๋„ ๋˜‘๊ฐ™์ด ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. -![Creating a python file](./images/helloworld.png) +![Creating a python file](../images/helloworld.png) ํ•˜๋ฃจ๋™์•ˆ ์˜ค๋ž˜ ์ฝ”๋”ฉ์„ ํ•œ ํ›„์— ์ฝ”๋“œ ํŽธ์ง‘๊ธฐ๋ฅผ ๋‹ซ๊ณ  ์‹ถ์Šต๋‹ˆ๊นŒ? ์ด๋ ‡๊ฒŒ ์—ด๋ฆฐ ํ”„๋กœ์ ํŠธ๋ฅผ ๋‹ซ์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. -![Closing project](./images/closing_opened_project.png) +![Closing project](../images/closing_opened_project.png) ์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ์„ค์ •์„ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค. ์ฝ”๋”ฉ์„ ์‹œ์ž‘ํ•ด ๋ด…์‹œ๋‹ค. @@ -244,7 +244,7 @@ Python ์Šคํฌ๋ฆฝํŠธ๋Š” Python ๋Œ€ํ™”ํ˜• ์…ธ ๋˜๋Š” ์ฝ”๋“œ ํŽธ์ง‘๊ธฐ์—์„œ ์ž‘์„ฑ ๋“ค์—ฌ์“ฐ๊ธฐ๋Š” ํ…์ŠคํŠธ์˜ ๊ณต๋ฐฑ์ž…๋‹ˆ๋‹ค. ๋งŽ์€ ์–ธ์–ด์—์„œ ๋“ค์—ฌ์“ฐ๊ธฐ๋Š” ์ฝ”๋“œ ๊ฐ€๋…์„ฑ์„ ๋†’์ด๋Š” ๋ฐ ์‚ฌ์šฉ๋˜์ง€๋งŒ Python์€ ๋“ค์—ฌ์“ฐ๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฝ”๋“œ ๋ธ”๋ก์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์—์„œ๋Š” ์ค‘๊ด„ํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋“ค์—ฌ์“ฐ๊ธฐ ๋Œ€์‹  ์ฝ”๋“œ ๋ธ”๋ก์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. Python ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ ํ”ํžˆ ๋ฐœ์ƒํ•˜๋Š” ๋ฒ„๊ทธ ์ค‘ ํ•˜๋‚˜๋Š” ์ž˜๋ชป๋œ ๋“ค์—ฌ์“ฐ๊ธฐ์ž…๋‹ˆ๋‹ค. -![Indentation Error](./images/indentation.png) +![Indentation Error](../images/indentation.png) ### ์ฃผ์„ @@ -372,7 +372,7 @@ Python ์‚ฌ์ „ ๊ฐœ์ฒด๋Š” ํ‚ค ๊ฐ’ ์Œ ํ˜•์‹์˜ ์ •๋ ฌ๋˜์ง€ ์•Š์€ ๋ฐ์ดํ„ฐ ๋ชจ ํŠน์ • ๋ฐ์ดํ„ฐ/๋ณ€์ˆ˜์˜ ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด **type** ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ํ„ฐ๋ฏธ๋„์—์„œ ๋‹ค์–‘ํ•œ Python ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค: -![Checking Data types](./images/checking_data_types.png) +![Checking Data types](../images/checking_data_types.png) ### Python ํŒŒ์ผ @@ -408,7 +408,7 @@ print(type((9.8, 3.14, 2.7))) # Tuple Python ํŒŒ์ผ์„ ์‹คํ–‰ํ•˜๋ ค๋ฉด ์•„๋ž˜ ์ด๋ฏธ์ง€๋ฅผ ํ™•์ธํ•˜์„ธ์š”. Visual Studio Code์—์„œ ๋…น์ƒ‰ ๋ฒ„ํŠผ์„ ์‹คํ–‰ํ•˜๊ฑฐ๋‚˜ ํ„ฐ๋ฏธ๋„์— *python helloworld.py*๋ฅผ ์ž…๋ ฅํ•˜์—ฌ Python ํŒŒ์ผ์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. -![Running python script](./images/running_python_script.png) +![Running python script](../images/running_python_script.png) ๐ŸŒ• ์ข‹์Šต๋‹ˆ๋‹ค. ๋‹น์‹ ์€ ๋ฐฉ๊ธˆ 1์ผ์ฐจ ๋„์ „์„ ์™„๋ฃŒํ–ˆ๊ณ  ๋‹น์‹ ์€ ์œ„๋Œ€ํ•œ ์—ฌ์ •์— ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ ๋‡Œ์™€ ๊ทผ์œก์„ ์œ„ํ•œ ๋ช‡ ๊ฐ€์ง€ ํ›ˆ๋ จ์„ ํ•ด๋ด…์‹œ๋‹ค. @@ -451,4 +451,4 @@ Python ํŒŒ์ผ์„ ์‹คํ–‰ํ•˜๋ ค๋ฉด ์•„๋ž˜ ์ด๋ฏธ์ง€๋ฅผ ํ™•์ธํ•˜์„ธ์š”. Visual Stu ๐ŸŽ‰ ์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค ! ๐ŸŽ‰ -[Day 2 >>](./02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) \ No newline at end of file +[Day 2 >>](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) \ No newline at end of file From 54af60ae4bc16430254fcfb961e2d3ce3abee55e Mon Sep 17 00:00:00 2001 From: jshyun1 Date: Thu, 8 Dec 2022 13:15:32 +0900 Subject: [PATCH 05/21] lang ko --- lang-ko/readme_ko.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang-ko/readme_ko.md b/lang-ko/readme_ko.md index 558efe95..bc628609 100644 --- a/lang-ko/readme_ko.md +++ b/lang-ko/readme_ko.md @@ -2,7 +2,7 @@ |# Day | Topics | |------|:---------------------------------------------------------:| -| 01 | [Introduction](../readme_ko.md)| +| 01 | [Introduction](./readme_ko.md)| | 02 | [Variables, Built-in Functions](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md)| | 03 | [Operators](../03_Day_Operators/03_operators.md)| | 04 | [Strings](../04_Day_Strings/04_strings.md)| From 9ca1e1b177acbef495a4132a5ce7c33ed0c63982 Mon Sep 17 00:00:00 2001 From: kjs1019 <68845945+kjs1019@users.noreply.github.com> Date: Thu, 8 Dec 2022 20:27:40 +0900 Subject: [PATCH 06/21] Delete korean --- korean | 1 - 1 file changed, 1 deletion(-) delete mode 100644 korean diff --git a/korean b/korean deleted file mode 100644 index 8b137891..00000000 --- a/korean +++ /dev/null @@ -1 +0,0 @@ - From 34124a1cc410bbce839c555f8bf90fc3f7a10702 Mon Sep 17 00:00:00 2001 From: kjs1019 <68845945+kjs1019@users.noreply.github.com> Date: Thu, 8 Dec 2022 20:27:55 +0900 Subject: [PATCH 07/21] Create readme.md --- korean/readme.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 korean/readme.md diff --git a/korean/readme.md b/korean/readme.md new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/korean/readme.md @@ -0,0 +1 @@ + From dc86d99e83a478afad26b4eca504f9ee59ebf805 Mon Sep 17 00:00:00 2001 From: kjs1019 <68845945+kjs1019@users.noreply.github.com> Date: Thu, 8 Dec 2022 20:28:20 +0900 Subject: [PATCH 08/21] Create 03_Day_Operators --- korean/03_Day_Operators | 317 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 317 insertions(+) create mode 100644 korean/03_Day_Operators diff --git a/korean/03_Day_Operators b/korean/03_Day_Operators new file mode 100644 index 00000000..0fcfeb99 --- /dev/null +++ b/korean/03_Day_Operators @@ -0,0 +1,317 @@ +
+

30 Days Of Python: Day 3 - Operators

+ + + + + Twitter Follow + + +Author: +Asabeneh Yetayeh
+ Second Edition: July, 2021 +
+
+ +[<< Day 2](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) | [Day 4 >>](../04_Day_Strings/04_strings.md) + +![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png) + +- [๐Ÿ“˜ Day 3](#-day-3) + - [Boolean](#boolean) + - [Operators](#operators) + - [Assignment Operators](#assignment-operators) + - [Arithmetic Operators:](#arithmetic-operators) + - [Comparison Operators](#comparison-operators) + - [Logical Operators](#logical-operators) + - [๐Ÿ’ป Exercises - Day 3](#-exercises---day-3) + +# ๐Ÿ“˜ Day 3 + +## Boolean + +A boolean data type represents one of the two values: _True_ or _False_. The use of these data types will be clear once we start using the comparison operator. The first letter **T** for True and **F** for False should be capital unlike JavaScript. +**Example: Boolean Values** + +```py +print(True) +print(False) +``` + +## Operators + +Python language supports several types of operators. In this section, we will focus on few of them. + +### Assignment Operators + +Assignment operators are used to assign values to variables. Let us take = as an example. Equal sign in mathematics shows that two values are equal, however in Python it means we are storing a value in a certain variable and we call it assignment or a assigning value to a variable. The table below shows the different types of python assignment operators, taken from [w3school](https://www.w3schools.com/python/python_operators.asp). + +![Assignment Operators](../images/assignment_operators.png) + +### Arithmetic Operators: + +- Addition(+): a + b +- Subtraction(-): a - b +- Multiplication(*): a * b +- Division(/): a / b +- Modulus(%): a % b +- Floor division(//): a // b +- Exponentiation(**): a ** b + +![Arithmetic Operators](../images/arithmetic_operators.png) + +**Example:Integers** + +```py +# Arithmetic Operations in Python +# Integers + +print('Addition: ', 1 + 2) # 3 +print('Subtraction: ', 2 - 1) # 1 +print('Multiplication: ', 2 * 3) # 6 +print ('Division: ', 4 / 2) # 2.0 Division in Python gives floating number +print('Division: ', 6 / 2) # 3.0 +print('Division: ', 7 / 2) # 3.5 +print('Division without the remainder: ', 7 // 2) # 3, gives without the floating number or without the remaining +print ('Division without the remainder: ',7 // 3) # 2 +print('Modulus: ', 3 % 2) # 1, Gives the remainder +print('Exponentiation: ', 2 ** 3) # 9 it means 2 * 2 * 2 +``` + +**Example:Floats** + +```py +# Floating numbers +print('Floating Point Number, PI', 3.14) +print('Floating Point Number, gravity', 9.81) +``` + +**Example:Complex numbers** + +```py +# Complex numbers +print('Complex number: ', 1 + 1j) +print('Multiplying complex numbers: ',(1 + 1j) * (1 - 1j)) +``` + +Let's declare a variable and assign a number data type. I am going to use single character variable but remember do not develop a habit of declaring such types of variables. Variable names should be all the time mnemonic. + +**Example:** + +```python +# Declaring the variable at the top first + +a = 3 # a is a variable name and 3 is an integer data type +b = 2 # b is a variable name and 3 is an integer data type + +# Arithmetic operations and assigning the result to a variable +total = a + b +diff = a - b +product = a * b +division = a / b +remainder = a % b +floor_division = a // b +exponential = a ** b + +# I should have used sum instead of total but sum is a built-in function - try to avoid overriding built-in functions +print(total) # if you do not label your print with some string, you never know where the result is coming from +print('a + b = ', total) +print('a - b = ', diff) +print('a * b = ', product) +print('a / b = ', division) +print('a % b = ', remainder) +print('a // b = ', floor_division) +print('a ** b = ', exponentiation) +``` + +**Example:** + +```py +print('== Addition, Subtraction, Multiplication, Division, Modulus ==') + +# Declaring values and organizing them together +num_one = 3 +num_two = 4 + +# Arithmetic operations +total = num_one + num_two +diff = num_two - num_one +product = num_one * num_two +div = num_two / num_one +remainder = num_two % num_one + +# Printing values with label +print('total: ', total) +print('difference: ', diff) +print('product: ', product) +print('division: ', div) +print('remainder: ', remainder) +``` + +Let us start start connecting the dots and start making use of what we already know to calculate (area, volume,density, weight, perimeter, distance, force). + +**Example:** + +```py +# Calculating area of a circle +radius = 10 # radius of a circle +area_of_circle = 3.14 * radius ** 2 # two * sign means exponent or power +print('Area of a circle:', area_of_circle) + +# Calculating area of a rectangle +length = 10 +width = 20 +area_of_rectangle = length * width +print('Area of rectangle:', area_of_rectangle) + +# Calculating a weight of an object +mass = 75 +gravity = 9.81 +weight = mass * gravity +print(weight, 'N') # Adding unit to the weight + +# Calculate the density of a liquid +mass = 75 # in Kg +volume = 0.075 # in cubic meter +density = mass / volume # 1000 Kg/m^3 + +``` + +### Comparison Operators + +In programming we compare values, we use comparison operators to compare two values. We check if a value is greater or less or equal to other value. The following table shows Python comparison operators which was taken from [w3shool](https://www.w3schools.com/python/python_operators.asp). + +![Comparison Operators](../images/comparison_operators.png) +**Example: Comparison Operators** + +```py +print(3 > 2) # True, because 3 is greater than 2 +print(3 >= 2) # True, because 3 is greater than 2 +print(3 < 2) # False, because 3 is greater than 2 +print(2 < 3) # True, because 2 is less than 3 +print(2 <= 3) # True, because 2 is less than 3 +print(3 == 2) # False, because 3 is not equal to 2 +print(3 != 2) # True, because 3 is not equal to 2 +print(len('mango') == len('avocado')) # False +print(len('mango') != len('avocado')) # True +print(len('mango') < len('avocado')) # True +print(len('milk') != len('meat')) # False +print(len('milk') == len('meat')) # True +print(len('tomato') == len('potato')) # True +print(len('python') > len('dragon')) # False + + +# Comparing something gives either a True or False + +print('True == True: ', True == True) +print('True == False: ', True == False) +print('False == False:', False == False) +``` + +In addition to the above comparison operator Python uses: + +- _is_: Returns true if both variables are the same object(x is y) +- _is not_: Returns true if both variables are not the same object(x is not y) +- _in_: Returns True if the queried list contains a certain item(x in y) +- _not in_: Returns True if the queried list doesn't have a certain item(x in y) + +```py +print('1 is 1', 1 is 1) # True - because the data values are the same +print('1 is not 2', 1 is not 2) # True - because 1 is not 2 +print('A in Asabeneh', 'A' in 'Asabeneh') # True - A found in the string +print('B in Asabeneh', 'B' in 'Asabeneh') # False - there is no uppercase B +print('coding' in 'coding for all') # True - because coding for all has the word coding +print('a in an:', 'a' in 'an') # True +print('4 is 2 ** 2:', 4 is 2 ** 2) # True +``` + +### Logical Operators + +Unlike other programming languages python uses keywords _and_, _or_ and _not_ for logical operators. Logical operators are used to combine conditional statements: + +![Logical Operators](../images/logical_operators.png) + +```py +print(3 > 2 and 4 > 3) # True - because both statements are true +print(3 > 2 and 4 < 3) # False - because the second statement is false +print(3 < 2 and 4 < 3) # False - because both statements are false +print('True and True: ', True and True) +print(3 > 2 or 4 > 3) # True - because both statements are true +print(3 > 2 or 4 < 3) # True - because one of the statements is true +print(3 < 2 or 4 < 3) # False - because both statements are false +print('True or False:', True or False) +print(not 3 > 2) # False - because 3 > 2 is true, then not True gives False +print(not True) # False - Negation, the not operator turns true to false +print(not False) # True +print(not not True) # True +print(not not False) # False + +``` + +๐ŸŒ• You have boundless energy. You have just completed day 3 challenges and you are three steps ahead on your way to greatness. Now do some exercises for your brain and your muscles. + +## ๐Ÿ’ป Exercises - Day 3 + +1. Declare your age as integer variable +2. Declare your height as a float variable +3. Declare a variable that store a complex number +4. Write a script that prompts the user to enter base and height of the triangle and calculate an area of this triangle (area = 0.5 x b x h). + +```py + Enter base: 20 + Enter height: 10 + The area of the triangle is 100 +``` + +5. Write a script that prompts the user to enter side a, side b, and side c of the triangle. Calculate the perimeter of the triangle (perimeter = a + b + c). + +```py +Enter side a: 5 +Enter side b: 4 +Enter side c: 3 +The perimeter of the triangle is 12 +``` + +6. Get length and width of a rectangle using prompt. Calculate its area (area = length x width) and perimeter (perimeter = 2 x (length + width)) +7. Get radius of a circle using prompt. Calculate the area (area = pi x r x r) and circumference (c = 2 x pi x r) where pi = 3.14. +8. Calculate the slope, x-intercept and y-intercept of y = 2x -2 +9. Slope is (m = y2-y1/x2-x1). Find the slope and [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance#:~:text=In%20mathematics%2C%20the%20Euclidean%20distance,being%20called%20the%20Pythagorean%20distance.) between point (2, 2) and point (6,10) +10. Compare the slopes in tasks 8 and 9. +11. Calculate the value of y (y = x^2 + 6x + 9). Try to use different x values and figure out at what x value y is going to be 0. +12. Find the length of 'python' and 'dragon' and make a falsy comparison statement. +13. Use _and_ operator to check if 'on' is found in both 'python' and 'dragon' +14. _I hope this course is not full of jargon_. Use _in_ operator to check if _jargon_ is in the sentence. +15. There is no 'on' in both dragon and python +16. Find the length of the text _python_ and convert the value to float and convert it to string +17. Even numbers are divisible by 2 and the remainder is zero. How do you check if a number is even or not using python? +18. Check if the floor division of 7 by 3 is equal to the int converted value of 2.7. +19. Check if type of '10' is equal to type of 10 +20. Check if int('9.8') is equal to 10 +21. Writ a script that prompts the user to enter hours and rate per hour. Calculate pay of the person? + +```py +Enter hours: 40 +Enter rate per hour: 28 +Your weekly earning is 1120 +``` + +22. Write a script that prompts the user to enter number of years. Calculate the number of seconds a person can live. Assume a person can live hundred years + +```py +Enter number of years you have lived: 100 +You have lived for 3153600000 seconds. +``` + +23. Write a Python script that displays the following table + +```py +1 1 1 1 1 +2 1 2 4 8 +3 1 3 9 27 +4 1 4 16 64 +5 1 5 25 125 +``` + +๐ŸŽ‰ CONGRATULATIONS ! ๐ŸŽ‰ + +[<< Day 2](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) | [Day 4 >>](../04_Day_Strings/04_strings.md) From aefe0a748cb0497e165d4f794a584671586f8e8e Mon Sep 17 00:00:00 2001 From: kjs1019 <68845945+kjs1019@users.noreply.github.com> Date: Thu, 8 Dec 2022 20:28:45 +0900 Subject: [PATCH 09/21] Delete 03_Day_Operators --- korean/03_Day_Operators | 317 ---------------------------------------- 1 file changed, 317 deletions(-) delete mode 100644 korean/03_Day_Operators diff --git a/korean/03_Day_Operators b/korean/03_Day_Operators deleted file mode 100644 index 0fcfeb99..00000000 --- a/korean/03_Day_Operators +++ /dev/null @@ -1,317 +0,0 @@ -
-

30 Days Of Python: Day 3 - Operators

- - - - - Twitter Follow - - -Author: -Asabeneh Yetayeh
- Second Edition: July, 2021 -
-
- -[<< Day 2](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) | [Day 4 >>](../04_Day_Strings/04_strings.md) - -![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png) - -- [๐Ÿ“˜ Day 3](#-day-3) - - [Boolean](#boolean) - - [Operators](#operators) - - [Assignment Operators](#assignment-operators) - - [Arithmetic Operators:](#arithmetic-operators) - - [Comparison Operators](#comparison-operators) - - [Logical Operators](#logical-operators) - - [๐Ÿ’ป Exercises - Day 3](#-exercises---day-3) - -# ๐Ÿ“˜ Day 3 - -## Boolean - -A boolean data type represents one of the two values: _True_ or _False_. The use of these data types will be clear once we start using the comparison operator. The first letter **T** for True and **F** for False should be capital unlike JavaScript. -**Example: Boolean Values** - -```py -print(True) -print(False) -``` - -## Operators - -Python language supports several types of operators. In this section, we will focus on few of them. - -### Assignment Operators - -Assignment operators are used to assign values to variables. Let us take = as an example. Equal sign in mathematics shows that two values are equal, however in Python it means we are storing a value in a certain variable and we call it assignment or a assigning value to a variable. The table below shows the different types of python assignment operators, taken from [w3school](https://www.w3schools.com/python/python_operators.asp). - -![Assignment Operators](../images/assignment_operators.png) - -### Arithmetic Operators: - -- Addition(+): a + b -- Subtraction(-): a - b -- Multiplication(*): a * b -- Division(/): a / b -- Modulus(%): a % b -- Floor division(//): a // b -- Exponentiation(**): a ** b - -![Arithmetic Operators](../images/arithmetic_operators.png) - -**Example:Integers** - -```py -# Arithmetic Operations in Python -# Integers - -print('Addition: ', 1 + 2) # 3 -print('Subtraction: ', 2 - 1) # 1 -print('Multiplication: ', 2 * 3) # 6 -print ('Division: ', 4 / 2) # 2.0 Division in Python gives floating number -print('Division: ', 6 / 2) # 3.0 -print('Division: ', 7 / 2) # 3.5 -print('Division without the remainder: ', 7 // 2) # 3, gives without the floating number or without the remaining -print ('Division without the remainder: ',7 // 3) # 2 -print('Modulus: ', 3 % 2) # 1, Gives the remainder -print('Exponentiation: ', 2 ** 3) # 9 it means 2 * 2 * 2 -``` - -**Example:Floats** - -```py -# Floating numbers -print('Floating Point Number, PI', 3.14) -print('Floating Point Number, gravity', 9.81) -``` - -**Example:Complex numbers** - -```py -# Complex numbers -print('Complex number: ', 1 + 1j) -print('Multiplying complex numbers: ',(1 + 1j) * (1 - 1j)) -``` - -Let's declare a variable and assign a number data type. I am going to use single character variable but remember do not develop a habit of declaring such types of variables. Variable names should be all the time mnemonic. - -**Example:** - -```python -# Declaring the variable at the top first - -a = 3 # a is a variable name and 3 is an integer data type -b = 2 # b is a variable name and 3 is an integer data type - -# Arithmetic operations and assigning the result to a variable -total = a + b -diff = a - b -product = a * b -division = a / b -remainder = a % b -floor_division = a // b -exponential = a ** b - -# I should have used sum instead of total but sum is a built-in function - try to avoid overriding built-in functions -print(total) # if you do not label your print with some string, you never know where the result is coming from -print('a + b = ', total) -print('a - b = ', diff) -print('a * b = ', product) -print('a / b = ', division) -print('a % b = ', remainder) -print('a // b = ', floor_division) -print('a ** b = ', exponentiation) -``` - -**Example:** - -```py -print('== Addition, Subtraction, Multiplication, Division, Modulus ==') - -# Declaring values and organizing them together -num_one = 3 -num_two = 4 - -# Arithmetic operations -total = num_one + num_two -diff = num_two - num_one -product = num_one * num_two -div = num_two / num_one -remainder = num_two % num_one - -# Printing values with label -print('total: ', total) -print('difference: ', diff) -print('product: ', product) -print('division: ', div) -print('remainder: ', remainder) -``` - -Let us start start connecting the dots and start making use of what we already know to calculate (area, volume,density, weight, perimeter, distance, force). - -**Example:** - -```py -# Calculating area of a circle -radius = 10 # radius of a circle -area_of_circle = 3.14 * radius ** 2 # two * sign means exponent or power -print('Area of a circle:', area_of_circle) - -# Calculating area of a rectangle -length = 10 -width = 20 -area_of_rectangle = length * width -print('Area of rectangle:', area_of_rectangle) - -# Calculating a weight of an object -mass = 75 -gravity = 9.81 -weight = mass * gravity -print(weight, 'N') # Adding unit to the weight - -# Calculate the density of a liquid -mass = 75 # in Kg -volume = 0.075 # in cubic meter -density = mass / volume # 1000 Kg/m^3 - -``` - -### Comparison Operators - -In programming we compare values, we use comparison operators to compare two values. We check if a value is greater or less or equal to other value. The following table shows Python comparison operators which was taken from [w3shool](https://www.w3schools.com/python/python_operators.asp). - -![Comparison Operators](../images/comparison_operators.png) -**Example: Comparison Operators** - -```py -print(3 > 2) # True, because 3 is greater than 2 -print(3 >= 2) # True, because 3 is greater than 2 -print(3 < 2) # False, because 3 is greater than 2 -print(2 < 3) # True, because 2 is less than 3 -print(2 <= 3) # True, because 2 is less than 3 -print(3 == 2) # False, because 3 is not equal to 2 -print(3 != 2) # True, because 3 is not equal to 2 -print(len('mango') == len('avocado')) # False -print(len('mango') != len('avocado')) # True -print(len('mango') < len('avocado')) # True -print(len('milk') != len('meat')) # False -print(len('milk') == len('meat')) # True -print(len('tomato') == len('potato')) # True -print(len('python') > len('dragon')) # False - - -# Comparing something gives either a True or False - -print('True == True: ', True == True) -print('True == False: ', True == False) -print('False == False:', False == False) -``` - -In addition to the above comparison operator Python uses: - -- _is_: Returns true if both variables are the same object(x is y) -- _is not_: Returns true if both variables are not the same object(x is not y) -- _in_: Returns True if the queried list contains a certain item(x in y) -- _not in_: Returns True if the queried list doesn't have a certain item(x in y) - -```py -print('1 is 1', 1 is 1) # True - because the data values are the same -print('1 is not 2', 1 is not 2) # True - because 1 is not 2 -print('A in Asabeneh', 'A' in 'Asabeneh') # True - A found in the string -print('B in Asabeneh', 'B' in 'Asabeneh') # False - there is no uppercase B -print('coding' in 'coding for all') # True - because coding for all has the word coding -print('a in an:', 'a' in 'an') # True -print('4 is 2 ** 2:', 4 is 2 ** 2) # True -``` - -### Logical Operators - -Unlike other programming languages python uses keywords _and_, _or_ and _not_ for logical operators. Logical operators are used to combine conditional statements: - -![Logical Operators](../images/logical_operators.png) - -```py -print(3 > 2 and 4 > 3) # True - because both statements are true -print(3 > 2 and 4 < 3) # False - because the second statement is false -print(3 < 2 and 4 < 3) # False - because both statements are false -print('True and True: ', True and True) -print(3 > 2 or 4 > 3) # True - because both statements are true -print(3 > 2 or 4 < 3) # True - because one of the statements is true -print(3 < 2 or 4 < 3) # False - because both statements are false -print('True or False:', True or False) -print(not 3 > 2) # False - because 3 > 2 is true, then not True gives False -print(not True) # False - Negation, the not operator turns true to false -print(not False) # True -print(not not True) # True -print(not not False) # False - -``` - -๐ŸŒ• You have boundless energy. You have just completed day 3 challenges and you are three steps ahead on your way to greatness. Now do some exercises for your brain and your muscles. - -## ๐Ÿ’ป Exercises - Day 3 - -1. Declare your age as integer variable -2. Declare your height as a float variable -3. Declare a variable that store a complex number -4. Write a script that prompts the user to enter base and height of the triangle and calculate an area of this triangle (area = 0.5 x b x h). - -```py - Enter base: 20 - Enter height: 10 - The area of the triangle is 100 -``` - -5. Write a script that prompts the user to enter side a, side b, and side c of the triangle. Calculate the perimeter of the triangle (perimeter = a + b + c). - -```py -Enter side a: 5 -Enter side b: 4 -Enter side c: 3 -The perimeter of the triangle is 12 -``` - -6. Get length and width of a rectangle using prompt. Calculate its area (area = length x width) and perimeter (perimeter = 2 x (length + width)) -7. Get radius of a circle using prompt. Calculate the area (area = pi x r x r) and circumference (c = 2 x pi x r) where pi = 3.14. -8. Calculate the slope, x-intercept and y-intercept of y = 2x -2 -9. Slope is (m = y2-y1/x2-x1). Find the slope and [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance#:~:text=In%20mathematics%2C%20the%20Euclidean%20distance,being%20called%20the%20Pythagorean%20distance.) between point (2, 2) and point (6,10) -10. Compare the slopes in tasks 8 and 9. -11. Calculate the value of y (y = x^2 + 6x + 9). Try to use different x values and figure out at what x value y is going to be 0. -12. Find the length of 'python' and 'dragon' and make a falsy comparison statement. -13. Use _and_ operator to check if 'on' is found in both 'python' and 'dragon' -14. _I hope this course is not full of jargon_. Use _in_ operator to check if _jargon_ is in the sentence. -15. There is no 'on' in both dragon and python -16. Find the length of the text _python_ and convert the value to float and convert it to string -17. Even numbers are divisible by 2 and the remainder is zero. How do you check if a number is even or not using python? -18. Check if the floor division of 7 by 3 is equal to the int converted value of 2.7. -19. Check if type of '10' is equal to type of 10 -20. Check if int('9.8') is equal to 10 -21. Writ a script that prompts the user to enter hours and rate per hour. Calculate pay of the person? - -```py -Enter hours: 40 -Enter rate per hour: 28 -Your weekly earning is 1120 -``` - -22. Write a script that prompts the user to enter number of years. Calculate the number of seconds a person can live. Assume a person can live hundred years - -```py -Enter number of years you have lived: 100 -You have lived for 3153600000 seconds. -``` - -23. Write a Python script that displays the following table - -```py -1 1 1 1 1 -2 1 2 4 8 -3 1 3 9 27 -4 1 4 16 64 -5 1 5 25 125 -``` - -๐ŸŽ‰ CONGRATULATIONS ! ๐ŸŽ‰ - -[<< Day 2](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) | [Day 4 >>](../04_Day_Strings/04_strings.md) From d43714ca16dc3b114e5ab80cbf5b8324ab5556c0 Mon Sep 17 00:00:00 2001 From: kjs1019 <68845945+kjs1019@users.noreply.github.com> Date: Thu, 8 Dec 2022 20:29:12 +0900 Subject: [PATCH 10/21] Create 03_operators.md --- korean/03_Day_Operators/03_operators.md | 317 ++++++++++++++++++++++++ 1 file changed, 317 insertions(+) create mode 100644 korean/03_Day_Operators/03_operators.md diff --git a/korean/03_Day_Operators/03_operators.md b/korean/03_Day_Operators/03_operators.md new file mode 100644 index 00000000..0fcfeb99 --- /dev/null +++ b/korean/03_Day_Operators/03_operators.md @@ -0,0 +1,317 @@ +
+

30 Days Of Python: Day 3 - Operators

+ + + + + Twitter Follow + + +Author: +Asabeneh Yetayeh
+ Second Edition: July, 2021 +
+
+ +[<< Day 2](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) | [Day 4 >>](../04_Day_Strings/04_strings.md) + +![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png) + +- [๐Ÿ“˜ Day 3](#-day-3) + - [Boolean](#boolean) + - [Operators](#operators) + - [Assignment Operators](#assignment-operators) + - [Arithmetic Operators:](#arithmetic-operators) + - [Comparison Operators](#comparison-operators) + - [Logical Operators](#logical-operators) + - [๐Ÿ’ป Exercises - Day 3](#-exercises---day-3) + +# ๐Ÿ“˜ Day 3 + +## Boolean + +A boolean data type represents one of the two values: _True_ or _False_. The use of these data types will be clear once we start using the comparison operator. The first letter **T** for True and **F** for False should be capital unlike JavaScript. +**Example: Boolean Values** + +```py +print(True) +print(False) +``` + +## Operators + +Python language supports several types of operators. In this section, we will focus on few of them. + +### Assignment Operators + +Assignment operators are used to assign values to variables. Let us take = as an example. Equal sign in mathematics shows that two values are equal, however in Python it means we are storing a value in a certain variable and we call it assignment or a assigning value to a variable. The table below shows the different types of python assignment operators, taken from [w3school](https://www.w3schools.com/python/python_operators.asp). + +![Assignment Operators](../images/assignment_operators.png) + +### Arithmetic Operators: + +- Addition(+): a + b +- Subtraction(-): a - b +- Multiplication(*): a * b +- Division(/): a / b +- Modulus(%): a % b +- Floor division(//): a // b +- Exponentiation(**): a ** b + +![Arithmetic Operators](../images/arithmetic_operators.png) + +**Example:Integers** + +```py +# Arithmetic Operations in Python +# Integers + +print('Addition: ', 1 + 2) # 3 +print('Subtraction: ', 2 - 1) # 1 +print('Multiplication: ', 2 * 3) # 6 +print ('Division: ', 4 / 2) # 2.0 Division in Python gives floating number +print('Division: ', 6 / 2) # 3.0 +print('Division: ', 7 / 2) # 3.5 +print('Division without the remainder: ', 7 // 2) # 3, gives without the floating number or without the remaining +print ('Division without the remainder: ',7 // 3) # 2 +print('Modulus: ', 3 % 2) # 1, Gives the remainder +print('Exponentiation: ', 2 ** 3) # 9 it means 2 * 2 * 2 +``` + +**Example:Floats** + +```py +# Floating numbers +print('Floating Point Number, PI', 3.14) +print('Floating Point Number, gravity', 9.81) +``` + +**Example:Complex numbers** + +```py +# Complex numbers +print('Complex number: ', 1 + 1j) +print('Multiplying complex numbers: ',(1 + 1j) * (1 - 1j)) +``` + +Let's declare a variable and assign a number data type. I am going to use single character variable but remember do not develop a habit of declaring such types of variables. Variable names should be all the time mnemonic. + +**Example:** + +```python +# Declaring the variable at the top first + +a = 3 # a is a variable name and 3 is an integer data type +b = 2 # b is a variable name and 3 is an integer data type + +# Arithmetic operations and assigning the result to a variable +total = a + b +diff = a - b +product = a * b +division = a / b +remainder = a % b +floor_division = a // b +exponential = a ** b + +# I should have used sum instead of total but sum is a built-in function - try to avoid overriding built-in functions +print(total) # if you do not label your print with some string, you never know where the result is coming from +print('a + b = ', total) +print('a - b = ', diff) +print('a * b = ', product) +print('a / b = ', division) +print('a % b = ', remainder) +print('a // b = ', floor_division) +print('a ** b = ', exponentiation) +``` + +**Example:** + +```py +print('== Addition, Subtraction, Multiplication, Division, Modulus ==') + +# Declaring values and organizing them together +num_one = 3 +num_two = 4 + +# Arithmetic operations +total = num_one + num_two +diff = num_two - num_one +product = num_one * num_two +div = num_two / num_one +remainder = num_two % num_one + +# Printing values with label +print('total: ', total) +print('difference: ', diff) +print('product: ', product) +print('division: ', div) +print('remainder: ', remainder) +``` + +Let us start start connecting the dots and start making use of what we already know to calculate (area, volume,density, weight, perimeter, distance, force). + +**Example:** + +```py +# Calculating area of a circle +radius = 10 # radius of a circle +area_of_circle = 3.14 * radius ** 2 # two * sign means exponent or power +print('Area of a circle:', area_of_circle) + +# Calculating area of a rectangle +length = 10 +width = 20 +area_of_rectangle = length * width +print('Area of rectangle:', area_of_rectangle) + +# Calculating a weight of an object +mass = 75 +gravity = 9.81 +weight = mass * gravity +print(weight, 'N') # Adding unit to the weight + +# Calculate the density of a liquid +mass = 75 # in Kg +volume = 0.075 # in cubic meter +density = mass / volume # 1000 Kg/m^3 + +``` + +### Comparison Operators + +In programming we compare values, we use comparison operators to compare two values. We check if a value is greater or less or equal to other value. The following table shows Python comparison operators which was taken from [w3shool](https://www.w3schools.com/python/python_operators.asp). + +![Comparison Operators](../images/comparison_operators.png) +**Example: Comparison Operators** + +```py +print(3 > 2) # True, because 3 is greater than 2 +print(3 >= 2) # True, because 3 is greater than 2 +print(3 < 2) # False, because 3 is greater than 2 +print(2 < 3) # True, because 2 is less than 3 +print(2 <= 3) # True, because 2 is less than 3 +print(3 == 2) # False, because 3 is not equal to 2 +print(3 != 2) # True, because 3 is not equal to 2 +print(len('mango') == len('avocado')) # False +print(len('mango') != len('avocado')) # True +print(len('mango') < len('avocado')) # True +print(len('milk') != len('meat')) # False +print(len('milk') == len('meat')) # True +print(len('tomato') == len('potato')) # True +print(len('python') > len('dragon')) # False + + +# Comparing something gives either a True or False + +print('True == True: ', True == True) +print('True == False: ', True == False) +print('False == False:', False == False) +``` + +In addition to the above comparison operator Python uses: + +- _is_: Returns true if both variables are the same object(x is y) +- _is not_: Returns true if both variables are not the same object(x is not y) +- _in_: Returns True if the queried list contains a certain item(x in y) +- _not in_: Returns True if the queried list doesn't have a certain item(x in y) + +```py +print('1 is 1', 1 is 1) # True - because the data values are the same +print('1 is not 2', 1 is not 2) # True - because 1 is not 2 +print('A in Asabeneh', 'A' in 'Asabeneh') # True - A found in the string +print('B in Asabeneh', 'B' in 'Asabeneh') # False - there is no uppercase B +print('coding' in 'coding for all') # True - because coding for all has the word coding +print('a in an:', 'a' in 'an') # True +print('4 is 2 ** 2:', 4 is 2 ** 2) # True +``` + +### Logical Operators + +Unlike other programming languages python uses keywords _and_, _or_ and _not_ for logical operators. Logical operators are used to combine conditional statements: + +![Logical Operators](../images/logical_operators.png) + +```py +print(3 > 2 and 4 > 3) # True - because both statements are true +print(3 > 2 and 4 < 3) # False - because the second statement is false +print(3 < 2 and 4 < 3) # False - because both statements are false +print('True and True: ', True and True) +print(3 > 2 or 4 > 3) # True - because both statements are true +print(3 > 2 or 4 < 3) # True - because one of the statements is true +print(3 < 2 or 4 < 3) # False - because both statements are false +print('True or False:', True or False) +print(not 3 > 2) # False - because 3 > 2 is true, then not True gives False +print(not True) # False - Negation, the not operator turns true to false +print(not False) # True +print(not not True) # True +print(not not False) # False + +``` + +๐ŸŒ• You have boundless energy. You have just completed day 3 challenges and you are three steps ahead on your way to greatness. Now do some exercises for your brain and your muscles. + +## ๐Ÿ’ป Exercises - Day 3 + +1. Declare your age as integer variable +2. Declare your height as a float variable +3. Declare a variable that store a complex number +4. Write a script that prompts the user to enter base and height of the triangle and calculate an area of this triangle (area = 0.5 x b x h). + +```py + Enter base: 20 + Enter height: 10 + The area of the triangle is 100 +``` + +5. Write a script that prompts the user to enter side a, side b, and side c of the triangle. Calculate the perimeter of the triangle (perimeter = a + b + c). + +```py +Enter side a: 5 +Enter side b: 4 +Enter side c: 3 +The perimeter of the triangle is 12 +``` + +6. Get length and width of a rectangle using prompt. Calculate its area (area = length x width) and perimeter (perimeter = 2 x (length + width)) +7. Get radius of a circle using prompt. Calculate the area (area = pi x r x r) and circumference (c = 2 x pi x r) where pi = 3.14. +8. Calculate the slope, x-intercept and y-intercept of y = 2x -2 +9. Slope is (m = y2-y1/x2-x1). Find the slope and [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance#:~:text=In%20mathematics%2C%20the%20Euclidean%20distance,being%20called%20the%20Pythagorean%20distance.) between point (2, 2) and point (6,10) +10. Compare the slopes in tasks 8 and 9. +11. Calculate the value of y (y = x^2 + 6x + 9). Try to use different x values and figure out at what x value y is going to be 0. +12. Find the length of 'python' and 'dragon' and make a falsy comparison statement. +13. Use _and_ operator to check if 'on' is found in both 'python' and 'dragon' +14. _I hope this course is not full of jargon_. Use _in_ operator to check if _jargon_ is in the sentence. +15. There is no 'on' in both dragon and python +16. Find the length of the text _python_ and convert the value to float and convert it to string +17. Even numbers are divisible by 2 and the remainder is zero. How do you check if a number is even or not using python? +18. Check if the floor division of 7 by 3 is equal to the int converted value of 2.7. +19. Check if type of '10' is equal to type of 10 +20. Check if int('9.8') is equal to 10 +21. Writ a script that prompts the user to enter hours and rate per hour. Calculate pay of the person? + +```py +Enter hours: 40 +Enter rate per hour: 28 +Your weekly earning is 1120 +``` + +22. Write a script that prompts the user to enter number of years. Calculate the number of seconds a person can live. Assume a person can live hundred years + +```py +Enter number of years you have lived: 100 +You have lived for 3153600000 seconds. +``` + +23. Write a Python script that displays the following table + +```py +1 1 1 1 1 +2 1 2 4 8 +3 1 3 9 27 +4 1 4 16 64 +5 1 5 25 125 +``` + +๐ŸŽ‰ CONGRATULATIONS ! ๐ŸŽ‰ + +[<< Day 2](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) | [Day 4 >>](../04_Day_Strings/04_strings.md) From abeb87a1989971621be103db58df5ca63822a3af Mon Sep 17 00:00:00 2001 From: kjs1019 <68845945+kjs1019@users.noreply.github.com> Date: Thu, 8 Dec 2022 21:14:09 +0900 Subject: [PATCH 11/21] Update 03_operators.md --- korean/03_Day_Operators/03_operators.md | 104 ++++++++++++------------ 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/korean/03_Day_Operators/03_operators.md b/korean/03_Day_Operators/03_operators.md index 0fcfeb99..d54c4981 100644 --- a/korean/03_Day_Operators/03_operators.md +++ b/korean/03_Day_Operators/03_operators.md @@ -17,50 +17,50 @@ ![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png) -- [๐Ÿ“˜ Day 3](#-day-3) - - [Boolean](#boolean) - - [Operators](#operators) - - [Assignment Operators](#assignment-operators) - - [Arithmetic Operators:](#arithmetic-operators) - - [Comparison Operators](#comparison-operators) - - [Logical Operators](#logical-operators) - - [๐Ÿ’ป Exercises - Day 3](#-exercises---day-3) +- [๐Ÿ“˜ 3์ผ์ฐจ](#3์ผ์ฐจ) + - [๋ถˆ๋ฆฌ์–ธ](#๋ถˆ๋ฆฌ์–ธ) + - [์—ฐ์‚ฐ์ž](#์—ฐ์‚ฐ์ž) + - [๋Œ€์ž… ์—ฐ์‚ฐ์ž](#๋Œ€์ž… ์—ฐ์‚ฐ์ž) + - [์‚ฐ์ˆ  ์—ฐ์‚ฐ์ž:](#์‚ฐ์ˆ  ์—ฐ์‚ฐ์ž) + - [๋น„๊ต ์—ฐ์‚ฐ์ž](#๋น„๊ต ์—ฐ์‚ฐ์ž) + - [๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž](#๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž) + - [๐Ÿ’ป 3์ผ์ฐจ: ์‹ค์Šต](#3์ผ์ฐจ: ์‹ค์Šต) -# ๐Ÿ“˜ Day 3 +# ๐Ÿ“˜ 3์ผ์ฐจ -## Boolean +## ๋ถˆ๋ฆฌ์–ธ -A boolean data type represents one of the two values: _True_ or _False_. The use of these data types will be clear once we start using the comparison operator. The first letter **T** for True and **F** for False should be capital unlike JavaScript. -**Example: Boolean Values** +๋ถˆ๋ฆฌ์–ธ ๋ฐ์ดํ„ฐ ํƒ€์ž…์€ True ๋˜๋Š” False ๋‘ ๊ฐ’ ์ค‘ ํ•˜๋‚˜๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. ๋น„๊ต ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ด ๋ฐ์ดํ„ฐ ํƒ€์ž…์˜ ์‚ฌ์šฉ์ด ๋ช…ํ™•ํ•ด์งˆ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ฒซ ๋ฒˆ์งธ ๋ฌธ์ž **T** ๋Š” ์ฐธ, **F** ๋Š” ๊ฑฐ์ง“์œผ๋กœ ํ‘œํ˜„๋˜๋Š” ์ž๋ฐ” ์Šคํฌ๋ฆฝํŠธ์™€ ๋‹ฌ๋ฆฌ ๋Œ€๋ฌธ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. +**์˜ˆ์‹œ: ๋ถˆ๋ฆฌ์–ธ ๊ฐ’** ```py print(True) print(False) ``` -## Operators +## ์—ฐ์‚ฐ์ž -Python language supports several types of operators. In this section, we will focus on few of them. +ํŒŒ์ด์ฌ์€ ๋ช‡ ๊ฐ€์ง€ ํƒ€์ž…์˜ ์—ฐ์‚ฐ์ž๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. ์ด ์„น์…˜์—์„œ ์ด๊ฒƒ์— ๋Œ€ํ•ด ์•Œ์•„๋ณผ ๊ฒƒ์ž…๋‹ˆ๋‹ค. -### Assignment Operators +### ๋Œ€์ž… ์—ฐ์‚ฐ์ž -Assignment operators are used to assign values to variables. Let us take = as an example. Equal sign in mathematics shows that two values are equal, however in Python it means we are storing a value in a certain variable and we call it assignment or a assigning value to a variable. The table below shows the different types of python assignment operators, taken from [w3school](https://www.w3schools.com/python/python_operators.asp). +๋Œ€์ž… ์—ฐ์‚ฐ์ž๋Š” ๋ณ€์ˆ˜์— ๊ฐ’์„ ๋Œ€์ž…ํ•  ๋•Œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. = ๋กœ ์˜ˆ์‹œ๋ฅผ ๋“ค์–ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ˆ˜ํ•™์—์„œ ๋“ฑํ˜ธ๋ž€ ๋‘ ๊ฐ’์ด ๋™์ผํ•˜๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•˜์ง€๋งŒ, ํŒŒ์ด์ฌ์—์„œ๋Š” ํŠน์ • ๋ณ€์ˆ˜๊ฐ€ ๊ฐ’์„ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉฐ, ์ด ๋ณ€์ˆ˜์— ๊ฐ’์„ ๋Œ€์ž…ํ•œ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ํ‘œ๋Š” [w3school](https://www.w3schools.com/python/python_operators.asp)์—์„œ ๊ฐ€์ ธ์˜จ ๋‹ค์–‘ํ•œ ์œ ํ˜•์˜ ํŒŒ์ด์ฌ ํ• ๋‹น ์—ฐ์‚ฐ์ž๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. -![Assignment Operators](../images/assignment_operators.png) +![๋Œ€์ž… ์—ฐ์‚ฐ์ž](../images/assignment_operators.png) -### Arithmetic Operators: +### ์‚ฐ์ˆ  ์—ฐ์‚ฐ์ž: -- Addition(+): a + b -- Subtraction(-): a - b -- Multiplication(*): a * b -- Division(/): a / b -- Modulus(%): a % b -- Floor division(//): a // b -- Exponentiation(**): a ** b +- ๋”ํ•˜๊ธฐ(+): a + b +- ๋นผ๊ธฐ(-): a - b +- ๊ณฑํ•˜๊ธฐ(*): a * b +- ๋‚˜๋ˆ„๊ธฐ(/): a / b +- ๋‚˜๋จธ์ง€ ์—ฐ์‚ฐ(%): a % b +- ๋ฒ„๋ฆผ ๋‚˜๋ˆ—์…ˆ(//): a // b +- ์ง€์ˆ˜(**): a ** b -![Arithmetic Operators](../images/arithmetic_operators.png) +![์‚ฐ์ˆ  ์—ฐ์‚ฐ์ž](../images/arithmetic_operators.png) -**Example:Integers** +**์˜ˆ์‹œ: Integers** ```py # Arithmetic Operations in Python @@ -69,16 +69,16 @@ Assignment operators are used to assign values to variables. Let us take = as an print('Addition: ', 1 + 2) # 3 print('Subtraction: ', 2 - 1) # 1 print('Multiplication: ', 2 * 3) # 6 -print ('Division: ', 4 / 2) # 2.0 Division in Python gives floating number +print ('Division: ', 4 / 2) # 2.0 ํŒŒ์ด์ฌ์˜ ๋‚˜๋ˆ„๊ธฐ๋Š” ๋ถ€๋™ ์†Œ์ˆ˜๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. print('Division: ', 6 / 2) # 3.0 print('Division: ', 7 / 2) # 3.5 -print('Division without the remainder: ', 7 // 2) # 3, gives without the floating number or without the remaining +print('Division without the remainder: ', 7 // 2) # 3, ๋ถ€๋™ ์†Œ์ˆ˜ ๋˜๋Š” ๋‚˜๋จธ์ง€๊ฐ€ ์—†๋Š” ๊ฐ’์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. print ('Division without the remainder: ',7 // 3) # 2 -print('Modulus: ', 3 % 2) # 1, Gives the remainder -print('Exponentiation: ', 2 ** 3) # 9 it means 2 * 2 * 2 +print('Modulus: ', 3 % 2) # 1, ๋‚˜๋จธ์ง€๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. +print('Exponentiation: ', 2 ** 3) # 9 2 * 2 * 2 ๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ``` -**Example:Floats** +**์˜ˆ์‹œ: Floats** ```py # Floating numbers @@ -86,7 +86,7 @@ print('Floating Point Number, PI', 3.14) print('Floating Point Number, gravity', 9.81) ``` -**Example:Complex numbers** +**์˜ˆ์‹œ: ๋ณต์†Œ์ˆ˜** ```py # Complex numbers @@ -94,17 +94,17 @@ print('Complex number: ', 1 + 1j) print('Multiplying complex numbers: ',(1 + 1j) * (1 - 1j)) ``` -Let's declare a variable and assign a number data type. I am going to use single character variable but remember do not develop a habit of declaring such types of variables. Variable names should be all the time mnemonic. +๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ์ˆซ์ž ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ๋Š” ๋‹จ์ผ ๋ฌธ์ž ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•  ๊ฒƒ์ด์ง€๋งŒ, ์ด๋Ÿฐ ์œ ํ˜•์˜ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๋Š” ์Šต๊ด€์€ ์ข‹์ง€ ์•Š๋‹ค๋Š” ๊ฒƒ์„ ๊ธฐ์–ตํ•˜์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋ณ€์ˆ˜ ์ด๋ฆ„์€ ํ•ญ์ƒ ๊ธฐ์–ตํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. **Example:** ```python -# Declaring the variable at the top first +# ์ฒซ ๋ฒˆ์งธ๋กœ ๋ณ€์ˆ˜๋ฅผ ๋จผ์ € ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค. -a = 3 # a is a variable name and 3 is an integer data type -b = 2 # b is a variable name and 3 is an integer data type +a = 3 # a๋Š” ๋ณ€์ˆ˜์˜ ์ด๋ฆ„์ด๋ฉฐ ์ •์ˆ˜ ๋ฐ์ดํ„ฐ ํƒ€์ž…์ž…๋‹ˆ๋‹ค. +b = 2 # b๋Š” ๋ณ€์ˆ˜์˜ ์ด๋ฆ„์ด๋ฉฐ ์ •์ˆ˜ ๋ฐ์ดํ„ฐ ํƒ€์ž…์ž…๋‹ˆ๋‹ค. -# Arithmetic operations and assigning the result to a variable +# ์‚ฐ์ˆ  ์—ฐ์‚ฐ ๋ฐ ๊ฒฐ๊ณผ๋ฅผ ๋ณ€์ˆ˜์— ๋Œ€์ž…ํ•ฉ๋‹ˆ๋‹ค. total = a + b diff = a - b product = a * b @@ -113,8 +113,8 @@ remainder = a % b floor_division = a // b exponential = a ** b -# I should have used sum instead of total but sum is a built-in function - try to avoid overriding built-in functions -print(total) # if you do not label your print with some string, you never know where the result is coming from +# sum ๋Œ€์‹  total์„ ์‚ฌ์šฉํ–ˆ์–ด์•ผ ํ•˜์ง€๋งŒ sum์€ ๋‚ด์žฅ ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค. ๋‚ด์žฅ ํ•จ์ˆ˜๋ฅผ ์žฌ์ •์˜ํ•˜์ง€ ์•Š๋„๋ก ํ•˜์‹ญ์‹œ์˜ค. +print(total) # ๋งŒ์•ฝ ๋ช‡๋ช‡ ์ถœ๋ ฅ์— ๋ฌธ์ž์—ด๋กœ ํ‘œ์‹œ๋ฅผ ํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, ์–ด๋””์„œ ๊ฒฐ๊ณผ๊ฐ€ ์˜ค๋Š”์ง€ ์•Œ์ง€ ๋ชปํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค. print('a + b = ', total) print('a - b = ', diff) print('a * b = ', product) @@ -129,18 +129,18 @@ print('a ** b = ', exponentiation) ```py print('== Addition, Subtraction, Multiplication, Division, Modulus ==') -# Declaring values and organizing them together +# ๊ฐ’์„ ์„ ์–ธํ•˜๊ณ  ํ•จ๊ป˜ ์ •๋ฆฌ num_one = 3 num_two = 4 -# Arithmetic operations +# ์‚ฐ์ˆ  ์—ฐ์‚ฐ total = num_one + num_two diff = num_two - num_one product = num_one * num_two div = num_two / num_one remainder = num_two % num_one -# Printing values with label +# ๋ ˆ์ด๋ธ”๋กœ ๊ฐ’ ์ถœ๋ ฅ print('total: ', total) print('difference: ', diff) print('product: ', product) @@ -148,36 +148,36 @@ print('division: ', div) print('remainder: ', remainder) ``` -Let us start start connecting the dots and start making use of what we already know to calculate (area, volume,density, weight, perimeter, distance, force). +์ด์ œ ์  ์—ฐ๊ฒฐ์„ ์‹œ์ž‘ํ•˜๊ณ  ์ด๋ฏธ ์•Œ๊ณ  ์žˆ๋Š” ๊ณ„์‚ฐ ๋ฐฉ๋ฒ•(๋ฉด์ , ๋ถ€ํ”ผ, ๋ฐ€๋„, ๋ฌด๊ฒŒ, ๋‘˜๋ ˆ, ๊ฑฐ๋ฆฌ, ํž˜)์„ ์‚ฌ์šฉํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. **Example:** ```py -# Calculating area of a circle -radius = 10 # radius of a circle -area_of_circle = 3.14 * radius ** 2 # two * sign means exponent or power +# ์›์˜ ๋„“์ด ๊ณ„์‚ฐ +radius = 10 # ์›์˜ ๋ฐ˜์ง€๋ฆ„ +area_of_circle = 3.14 * radius ** 2 # ๋‘ ๊ฐœ์˜ * ๊ธฐํ˜ธ๋Š” ์ง€์ˆ˜๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค print('Area of a circle:', area_of_circle) -# Calculating area of a rectangle +# ์ง์‚ฌ๊ฐํ˜•์˜ ๋„“์ด ๊ณ„์‚ฐ length = 10 width = 20 area_of_rectangle = length * width print('Area of rectangle:', area_of_rectangle) -# Calculating a weight of an object +# ๊ฐœ์ฒด์˜ ๋ฌด๊ฒŒ ๊ณ„์‚ฐ mass = 75 gravity = 9.81 weight = mass * gravity -print(weight, 'N') # Adding unit to the weight +print(weight, 'N') # ๋ฌด๊ฒŒ์— ๋‹จ์œ„ ์ถ”๊ฐ€ -# Calculate the density of a liquid +# ์•ก์ฒด์˜ ๋ฐ€๋„ ๊ณ„์‚ฐ mass = 75 # in Kg volume = 0.075 # in cubic meter density = mass / volume # 1000 Kg/m^3 ``` -### Comparison Operators +### ๋น„๊ต ์—ฐ์‚ฐ์ž In programming we compare values, we use comparison operators to compare two values. We check if a value is greater or less or equal to other value. The following table shows Python comparison operators which was taken from [w3shool](https://www.w3schools.com/python/python_operators.asp). From d0d51e2673f5acb0d328110201e78773bfdd84f0 Mon Sep 17 00:00:00 2001 From: kjs1019 <68845945+kjs1019@users.noreply.github.com> Date: Thu, 8 Dec 2022 21:43:35 +0900 Subject: [PATCH 12/21] Update 03_operators.md --- korean/03_Day_Operators/03_operators.md | 144 ++++++++++++------------ 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/korean/03_Day_Operators/03_operators.md b/korean/03_Day_Operators/03_operators.md index d54c4981..e50972fc 100644 --- a/korean/03_Day_Operators/03_operators.md +++ b/korean/03_Day_Operators/03_operators.md @@ -20,11 +20,11 @@ - [๐Ÿ“˜ 3์ผ์ฐจ](#3์ผ์ฐจ) - [๋ถˆ๋ฆฌ์–ธ](#๋ถˆ๋ฆฌ์–ธ) - [์—ฐ์‚ฐ์ž](#์—ฐ์‚ฐ์ž) - - [๋Œ€์ž… ์—ฐ์‚ฐ์ž](#๋Œ€์ž… ์—ฐ์‚ฐ์ž) - - [์‚ฐ์ˆ  ์—ฐ์‚ฐ์ž:](#์‚ฐ์ˆ  ์—ฐ์‚ฐ์ž) - - [๋น„๊ต ์—ฐ์‚ฐ์ž](#๋น„๊ต ์—ฐ์‚ฐ์ž) - - [๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž](#๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž) - - [๐Ÿ’ป 3์ผ์ฐจ: ์‹ค์Šต](#3์ผ์ฐจ: ์‹ค์Šต) + - [๋Œ€์ž… ์—ฐ์‚ฐ์ž](#๋Œ€์ž…-์—ฐ์‚ฐ์ž) + - [์‚ฐ์ˆ  ์—ฐ์‚ฐ์ž:](#์‚ฐ์ˆ -์—ฐ์‚ฐ์ž) + - [๋น„๊ต ์—ฐ์‚ฐ์ž](#๋น„๊ต-์—ฐ์‚ฐ์ž) + - [๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž](#๋…ผ๋ฆฌ-์—ฐ์‚ฐ์ž) + - [๐Ÿ’ป 3์ผ์ฐจ: ์‹ค์Šต](3์ผ์ฐจ:-์‹ค์Šต) # ๐Ÿ“˜ 3์ผ์ฐจ @@ -179,83 +179,83 @@ density = mass / volume # 1000 Kg/m^3 ### ๋น„๊ต ์—ฐ์‚ฐ์ž -In programming we compare values, we use comparison operators to compare two values. We check if a value is greater or less or equal to other value. The following table shows Python comparison operators which was taken from [w3shool](https://www.w3schools.com/python/python_operators.asp). +ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ์šฐ๋ฆฌ๋Š” ๋น„๊ต ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‘ ๊ฐ’์„ ๋น„๊ตํ•ฉ๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๋Š” ๊ฐ’์ด ๋‹ค๋ฅธ ๊ฐ’๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ํ‘œ๋Š”[w3shool](https://www.w3schools.com/python/python_operators.asp)์—์„œ ๊ฐ€์ ธ์˜จ ํŒŒ์ด์ฌ์˜ ๋น„๊ต ์—ฐ์‚ฐ์ž๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. ![Comparison Operators](../images/comparison_operators.png) -**Example: Comparison Operators** +**Example: ๋น„๊ต ์—ฐ์‚ฐ์ž** ```py -print(3 > 2) # True, because 3 is greater than 2 -print(3 >= 2) # True, because 3 is greater than 2 -print(3 < 2) # False, because 3 is greater than 2 -print(2 < 3) # True, because 2 is less than 3 -print(2 <= 3) # True, because 2 is less than 3 -print(3 == 2) # False, because 3 is not equal to 2 -print(3 != 2) # True, because 3 is not equal to 2 -print(len('mango') == len('avocado')) # False -print(len('mango') != len('avocado')) # True -print(len('mango') < len('avocado')) # True -print(len('milk') != len('meat')) # False -print(len('milk') == len('meat')) # True -print(len('tomato') == len('potato')) # True -print(len('python') > len('dragon')) # False - - -# Comparing something gives either a True or False +print(3 > 2) # ์ฐธ, 3์ด 2๋ณด๋‹ค ํฌ๊ธฐ ๋•Œ๋ฌธ์— +print(3 >= 2) # ์ฐธ, 3์ด 2๋ณด๋‹ค ํฌ๊ธฐ ๋•Œ๋ฌธ์— +print(3 < 2) # ๊ฑฐ์ง“, 3์ด ๋” ํฌ๊ธฐ ๋•Œ๋ฌธ์— +print(2 < 3) # ์ฐธ, 2๊ฐ€ 3๋ณด๋‹ค ์ž‘๊ธฐ ๋•Œ๋ฌธ์— +print(2 <= 3) # ์ฐธ, 2๊ฐ€ 3๋ณด๋‹ค ์ž‘๊ธฐ ๋•Œ๋ฌธ์— +print(3 == 2) # ๊ฑฐ์ง“, 3๊ณผ 2๋Š” ๊ฐ™์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— +print(3 != 2) # ์ฐธ, 3์€ 2์™€ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— +print(len('mango') == len('avocado')) # ๊ฑฐ์ง“ +print(len('mango') != len('avocado')) # ์ฐธ +print(len('mango') < len('avocado')) # ์ฐธ +print(len('milk') != len('meat')) # ๊ฑฐ์ง“ +print(len('milk') == len('meat')) # ์ฐธ +print(len('tomato') == len('potato')) # ์ฐธ +print(len('python') > len('dragon')) # ๊ฑฐ์ง“ + + +# ๋ฌด์–ธ๊ฐ€๋ฅผ ๋น„๊ตํ•˜๋ฉด ์ฐธ ๋˜๋Š” ๊ฑฐ์ง“์ด ๋ฉ๋‹ˆ๋‹ค. print('True == True: ', True == True) print('True == False: ', True == False) print('False == False:', False == False) ``` -In addition to the above comparison operator Python uses: +์œ„์˜ ๋น„๊ต ์—ฐ์‚ฐ์ž ์™ธ์— ํŒŒ์ด์ฌ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค: -- _is_: Returns true if both variables are the same object(x is y) -- _is not_: Returns true if both variables are not the same object(x is not y) -- _in_: Returns True if the queried list contains a certain item(x in y) -- _not in_: Returns True if the queried list doesn't have a certain item(x in y) +- _is_: ๋‘ ๋ณ€์ˆ˜๊ฐ€ ๋™์ผํ•  ๊ฒฝ์šฐ ์ฐธ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.(x is y) +- _is not_: ๋‘ ๋ณ€์ˆ˜๊ฐ€ ๋™์ผํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ ์ฐธ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.(x is not y) +- _in_: ์ œ์‹œ๋œ ๋ชฉ๋ก์— ํŠน์ • ํ•ญ๋ชฉ์ด ํฌํ•จ๋œ ๊ฒฝ์šฐ ์ฐธ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.(x in y) +- _not in_: ์ œ์‹œ๋œ ๋ชฉ๋ก์— ํŠน์ • ํ•ญ๋ชฉ์ด ์—†์œผ๋ฉด ์ฐธ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.(x in y) ```py -print('1 is 1', 1 is 1) # True - because the data values are the same -print('1 is not 2', 1 is not 2) # True - because 1 is not 2 -print('A in Asabeneh', 'A' in 'Asabeneh') # True - A found in the string -print('B in Asabeneh', 'B' in 'Asabeneh') # False - there is no uppercase B -print('coding' in 'coding for all') # True - because coding for all has the word coding -print('a in an:', 'a' in 'an') # True -print('4 is 2 ** 2:', 4 is 2 ** 2) # True +print('1 is 1', 1 is 1) # ์ฐธ - ๋ฐ์ดํ„ฐ ๊ฐ’์ด ๋™์ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— +print('1 is not 2', 1 is not 2) # ์ฐธ - 1๊ณผ 2๋Š” ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— +print('A in Asabeneh', 'A' in 'Asabeneh') # ์ฐธ - ๋ฌธ์ž์—ด์—์„œ A๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค +print('B in Asabeneh', 'B' in 'Asabeneh') # ๊ฑฐ์ง“ - ๋Œ€๋ฌธ์ž B๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค +print('coding' in 'coding for all') # ์ฐธ - coding์ด๋ผ๋Š” ๋‹จ์–ด๋ฅผ coding for all์ด ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— +print('a in an:', 'a' in 'an') # ์ฐธ +print('4 is 2 ** 2:', 4 is 2 ** 2) # ์ฐธ ``` -### Logical Operators +### ๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž -Unlike other programming languages python uses keywords _and_, _or_ and _not_ for logical operators. Logical operators are used to combine conditional statements: +๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์™€ ๋‹ฌ๋ฆฌ ํŒŒ์ด์ฌ์€ ๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž๋ฅผ ์œ„ํ•ด _and_, _or_, _not_ ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์กฐ๊ฑด๋ฌธ์„ ๊ฒฐํ•ฉํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ![Logical Operators](../images/logical_operators.png) ```py -print(3 > 2 and 4 > 3) # True - because both statements are true -print(3 > 2 and 4 < 3) # False - because the second statement is false -print(3 < 2 and 4 < 3) # False - because both statements are false +print(3 > 2 and 4 > 3) # ์ฐธ - ๋‘ ๊ฐœ์˜ ๋ฌธ์žฅ์ด ์ฐธ์ด๊ธฐ ๋•Œ๋ฌธ์— +print(3 > 2 and 4 < 3) # ๊ฑฐ์ง“ - ๋‘ ๋ฒˆ์งธ ๋ฌธ์žฅ์ด ๊ฑฐ์ง“์ด๊ธฐ ๋•Œ๋ฌธ์— +print(3 < 2 and 4 < 3) # ๊ฑฐ์ง“ - ๋‘ ๊ฐ€์ง€ ๋ฌธ์žฅ ๋ชจ๋‘ ๊ฑฐ์ง“์ด๊ธฐ ๋•Œ๋ฌธ์— print('True and True: ', True and True) -print(3 > 2 or 4 > 3) # True - because both statements are true -print(3 > 2 or 4 < 3) # True - because one of the statements is true -print(3 < 2 or 4 < 3) # False - because both statements are false +print(3 > 2 or 4 > 3) # ์ฐธ - ๋‘ ๊ฐ€์ง€ ๋ฌธ์žฅ ๋ชจ๋‘ ์ฐธ์ด๊ธฐ ๋•Œ๋ฌธ์— +print(3 > 2 or 4 < 3) # ์ฐธ - ๋‘ ๊ฐ€์ง€ ์ค‘ ํ•˜๋‚˜์˜ ๋ฌธ์žฅ์ด ์ฐธ์ด๊ธฐ ๋•Œ๋ฌธ์— +print(3 < 2 or 4 < 3) # ๊ฑฐ์ง“ - ๋‘ ๊ฐ€์ง€ ๋ฌธ์žฅ ๋ชจ๋‘ ๊ฑฐ์ง“์ด๊ธฐ ๋•Œ๋ฌธ์— print('True or False:', True or False) -print(not 3 > 2) # False - because 3 > 2 is true, then not True gives False -print(not True) # False - Negation, the not operator turns true to false +print(not 3 > 2) # ๊ฑฐ์ง“ - 3์ด 2๋ณด๋‹ค ํฐ ๊ฒƒ์€ ์ฐธ์ด๊ธฐ ๋•Œ๋ฌธ์—, ์ฐธ์ด ์•„๋‹ ๊ฒฝ์šฐ ๊ฑฐ์ง“์„ ์ค๋‹ˆ๋‹ค. +print(not True) # ๊ฑฐ์ง“ - ๋ถ€์ •์œผ๋กœ ์ฐธ์—์„œ ๊ฑฐ์ง“์œผ๋กœ ๋ฐ”๋€๋‹ˆ๋‹ค. print(not False) # True print(not not True) # True print(not not False) # False ``` -๐ŸŒ• You have boundless energy. You have just completed day 3 challenges and you are three steps ahead on your way to greatness. Now do some exercises for your brain and your muscles. +๐ŸŒ• ๋‹น์‹ ์€ ๋ฌดํ•œํ•œ ์—๋„ˆ์ง€๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์š”. ์—ฌ๋Ÿฌ๋ถ„์€ ์ด์ œ ๋ง‰ 3์ผ์ฐจ ๋„์ „์„ ๋งˆ์ณค๊ณ  ์œ„๋Œ€ํ•จ์œผ๋กœ ๊ฐ€๋Š” ๊ธธ์— ์„ธ ๊ฑธ์Œ ์•ž์„œ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ ์—ฌ๋Ÿฌ๋ถ„์˜ ๋‡Œ์™€ ๊ทผ์œก์„ ์œ„ํ•œ ์šด๋™์„ ํ•˜์„ธ์š”. -## ๐Ÿ’ป Exercises - Day 3 +## ๐Ÿ’ป 3์ผ์ฐจ: ์‹ค์Šต -1. Declare your age as integer variable -2. Declare your height as a float variable -3. Declare a variable that store a complex number -4. Write a script that prompts the user to enter base and height of the triangle and calculate an area of this triangle (area = 0.5 x b x h). +1. ๋‚˜์ด๋ฅผ ์ •์ˆ˜ ๋ณ€์ˆ˜๋กœ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค. +2. ์ž์‹ ์˜ ํ‚ค๋ฅผ ํ”Œ๋กœํŠธ ๋ณ€์ˆ˜๋กœ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค. +3. ๋ณต์†Œ์ˆ˜๋ฅผ ์ €์žฅํ•˜๋Š” ๋ณ€์ˆ˜ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค. +4. ์‚ผ๊ฐํ˜•์˜ ๋ฐ‘๋ฉด๊ณผ ๋†’์ด๋ฅผ ์ž…๋ ฅํ•˜๋„๋ก ์‚ฌ์šฉ์ž์—๊ฒŒ ์ง€์‹œํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ์ด ์‚ผ๊ฐํ˜•์˜ ๋ฉด์ (๋ฉด์  = 0.5 x b x h)์„ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค. ```py Enter base: 20 @@ -263,7 +263,7 @@ print(not not False) # False The area of the triangle is 100 ``` -5. Write a script that prompts the user to enter side a, side b, and side c of the triangle. Calculate the perimeter of the triangle (perimeter = a + b + c). +5. ์‚ผ๊ฐํ˜•์˜ ์ธก๋ฉด a, ์ธก๋ฉด b, ์ธก๋ฉด c๋ฅผ ์ž…๋ ฅํ•˜๋ผ๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ํ‘œ์‹œํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. ์‚ผ๊ฐํ˜•์˜ ๋‘˜๋ ˆ(์ง€๋ฆ„ = a + b + c)๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค. ```py Enter side a: 5 @@ -272,22 +272,22 @@ Enter side c: 3 The perimeter of the triangle is 12 ``` -6. Get length and width of a rectangle using prompt. Calculate its area (area = length x width) and perimeter (perimeter = 2 x (length + width)) -7. Get radius of a circle using prompt. Calculate the area (area = pi x r x r) and circumference (c = 2 x pi x r) where pi = 3.14. -8. Calculate the slope, x-intercept and y-intercept of y = 2x -2 -9. Slope is (m = y2-y1/x2-x1). Find the slope and [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance#:~:text=In%20mathematics%2C%20the%20Euclidean%20distance,being%20called%20the%20Pythagorean%20distance.) between point (2, 2) and point (6,10) -10. Compare the slopes in tasks 8 and 9. -11. Calculate the value of y (y = x^2 + 6x + 9). Try to use different x values and figure out at what x value y is going to be 0. -12. Find the length of 'python' and 'dragon' and make a falsy comparison statement. -13. Use _and_ operator to check if 'on' is found in both 'python' and 'dragon' -14. _I hope this course is not full of jargon_. Use _in_ operator to check if _jargon_ is in the sentence. -15. There is no 'on' in both dragon and python -16. Find the length of the text _python_ and convert the value to float and convert it to string -17. Even numbers are divisible by 2 and the remainder is zero. How do you check if a number is even or not using python? -18. Check if the floor division of 7 by 3 is equal to the int converted value of 2.7. -19. Check if type of '10' is equal to type of 10 -20. Check if int('9.8') is equal to 10 -21. Writ a script that prompts the user to enter hours and rate per hour. Calculate pay of the person? +6. ํ”„๋กฌํ”„ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ง์‚ฌ๊ฐํ˜•์˜ ๊ธธ์ด์™€ ๋„ˆ๋น„๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค. ๋ฉด์ (๋ฉด์  = ๊ธธ์ด x ํญ) ๋ฐ ๋‘˜๋ ˆ(๋ฉด์  = 2 x (๊ธธ์ด + ํญ)) ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค. +7. ํ”„๋กฌํ”„ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์›์˜ ๋ฐ˜์ง€๋ฆ„์„ ๊ตฌํ•ฉ๋‹ˆ๋‹ค. ๋ฉด์ (๋ฉด์  = ํ”ฝ์Šค r x r)๊ณผ ์›์ฃผ(c = 2 x ํ”ฝ์Šค r)๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ pi = 3.14์ž…๋‹ˆ๋‹ค. +8. y = 2x-2์˜ ๊ธฐ์šธ๊ธฐ, x-์ œ๊ณฑ ๋ฐ y-์ œ๊ณฑ์„ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค. +9. ๊ธฐ์šธ๊ธฐ๋Š” (m = y2-y1/x2-x1)์ž…๋‹ˆ๋‹ค. ๊ธฐ์šธ๊ธฐ์™€ [์œ ํด๋ฆฌ๋“œ ๊ฑฐ๋ฆฌ](https://en.wikipedia.org/wiki/Euclidean_distance#:~:text=In%20mathematics%2C%20the%20Euclidean%20distance,being%20called%20the%20Pythagorean%20distance.) ์ (2,2)๊ณผ ์ (6,10) ์‚ฌ์ด๋ฅผ ๊ตฌํ•ฉ๋‹ˆ๋‹ค. +10. ๊ณผ์ œ 8๊ณผ 9์˜ ๊ธฐ์šธ๊ธฐ๋ฅผ ๋น„๊ตํ•ฉ๋‹ˆ๋‹ค. +11. y ๊ฐ’(y = x^2 + 6x + 9)์„ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค. ๋‹ค๋ฅธ x ๊ฐ’์„ ์‚ฌ์šฉํ•˜๊ณ  y ๊ฐ’์ด 0์ด ๋˜๋Š” x ๊ฐ’์„ ๊ณ„์‚ฐํ•ด ๋ณด์‹ญ์‹œ์˜ค. +12. 'python'๊ณผ 'dragon'์˜ ๊ธธ์ด๋ฅผ ์ฐพ์•„ ๊ฑฐ์ง“ ๋น„๊ต๋ฅผ ํ•ฉ๋‹ˆ๋‹ค. +13. _and_ ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 'python'๊ณผ 'dragon' ๋ชจ๋‘์— 'on'์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. +14. _๋‚˜๋Š” ์ด ๊ฐ•์ขŒ๊ฐ€ ์ „๋ฌธ์šฉ์–ด๋กœ ๊ฐ€๋“ํ•˜์ง€ ์•Š๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค. _in_ ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ _jargon_ ์ด ๋ฌธ์žฅ์— ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. +15. dragon๊ณผ python ๋ชจ๋‘ 'On'์ด ์—†์Šต๋‹ˆ๋‹ค. +16. _python_ ํ…์ŠคํŠธ์˜ ๊ธธ์ด๋ฅผ ์ฐพ์•„์„œ ๊ฐ’์„ float๋กœ ๋ณ€ํ™˜ํ•˜๊ณ  ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค. +17. ์ง์ˆ˜๋Š” 2๋กœ ๋‚˜๋ˆ„๊ณ  ๋‚˜๋จธ์ง€๋Š” 0์ž…๋‹ˆ๋‹ค. ํŒŒ์ด์ฌ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ˆซ์ž๊ฐ€ ์ง์ˆ˜์ธ์ง€ ์•„๋‹Œ์ง€ ์–ด๋–ป๊ฒŒ ํ™•์ธํ•ฉ๋‹ˆ๊นŒ? +18. 7 x 3์˜ ๋‚˜๋ˆ—์…ˆ ๋ฒ„๋ฆผ์ด 2.7์˜ int ๋ณ€ํ™˜๊ฐ’๊ณผ ๋™์ผํ•œ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. +19. '10'์˜ ์œ ํ˜•์ด 10์˜ ์œ ํ˜•๊ณผ ๋™์ผํ•œ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. +20. if int('9)๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.8')๋Š” 10๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. +21. ์‚ฌ์šฉ์ž์—๊ฒŒ ์‹œ๊ฐ„ ๋ฐ ์‹œ๊ฐ„๋‹น ์š”๊ธˆ์„ ์ž…๋ ฅํ•˜๋„๋ก ์š”์ฒญํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ์‚ฌ๋žŒ์˜ ๊ธ‰์—ฌ๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๊นŒ? ```py Enter hours: 40 @@ -295,14 +295,14 @@ Enter rate per hour: 28 Your weekly earning is 1120 ``` -22. Write a script that prompts the user to enter number of years. Calculate the number of seconds a person can live. Assume a person can live hundred years +22. ์‚ฌ์šฉ์ž์—๊ฒŒ ๋…„ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜๋„๋ก ์š”์ฒญํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ๋žŒ์ด ์‚ด ์ˆ˜ ์žˆ๋Š” ์‹œ๊ฐ„์„ ์ดˆ ๋‹จ์œ„๋กœ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ๋žŒ์ด 100๋…„์„ ์‚ด ์ˆ˜ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ์‹œ๋‹ค. ```py Enter number of years you have lived: 100 You have lived for 3153600000 seconds. ``` -23. Write a Python script that displays the following table +23. ๋‹ค์Œ์„ ํ‘œ์‹œํ•˜๋Š” ํŒŒ์ด์ฌ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. ```py 1 1 1 1 1 @@ -312,6 +312,6 @@ You have lived for 3153600000 seconds. 5 1 5 25 125 ``` -๐ŸŽ‰ CONGRATULATIONS ! ๐ŸŽ‰ +๐ŸŽ‰ ์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค ! ๐ŸŽ‰ [<< Day 2](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) | [Day 4 >>](../04_Day_Strings/04_strings.md) From 2eb6c20726b0559b49988451f6e4ef94da0f5995 Mon Sep 17 00:00:00 2001 From: kjs1019 <68845945+kjs1019@users.noreply.github.com> Date: Thu, 8 Dec 2022 21:52:31 +0900 Subject: [PATCH 13/21] Update 03_operators.md --- korean/03_Day_Operators/03_operators.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/korean/03_Day_Operators/03_operators.md b/korean/03_Day_Operators/03_operators.md index e50972fc..1cfff93d 100644 --- a/korean/03_Day_Operators/03_operators.md +++ b/korean/03_Day_Operators/03_operators.md @@ -17,14 +17,14 @@ ![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png) -- [๐Ÿ“˜ 3์ผ์ฐจ](#3์ผ์ฐจ) +- [๐Ÿ“˜ 3์ผ์ฐจ](#-3์ผ์ฐจ) - [๋ถˆ๋ฆฌ์–ธ](#๋ถˆ๋ฆฌ์–ธ) - [์—ฐ์‚ฐ์ž](#์—ฐ์‚ฐ์ž) - [๋Œ€์ž… ์—ฐ์‚ฐ์ž](#๋Œ€์ž…-์—ฐ์‚ฐ์ž) - [์‚ฐ์ˆ  ์—ฐ์‚ฐ์ž:](#์‚ฐ์ˆ -์—ฐ์‚ฐ์ž) - [๋น„๊ต ์—ฐ์‚ฐ์ž](#๋น„๊ต-์—ฐ์‚ฐ์ž) - [๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž](#๋…ผ๋ฆฌ-์—ฐ์‚ฐ์ž) - - [๐Ÿ’ป 3์ผ์ฐจ: ์‹ค์Šต](3์ผ์ฐจ:-์‹ค์Šต) + - [๐Ÿ’ป 3์ผ์ฐจ: ์‹ค์Šต](#-3์ผ์ฐจ-์‹ค์Šต) # ๐Ÿ“˜ 3์ผ์ฐจ @@ -250,7 +250,7 @@ print(not not False) # False ๐ŸŒ• ๋‹น์‹ ์€ ๋ฌดํ•œํ•œ ์—๋„ˆ์ง€๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์š”. ์—ฌ๋Ÿฌ๋ถ„์€ ์ด์ œ ๋ง‰ 3์ผ์ฐจ ๋„์ „์„ ๋งˆ์ณค๊ณ  ์œ„๋Œ€ํ•จ์œผ๋กœ ๊ฐ€๋Š” ๊ธธ์— ์„ธ ๊ฑธ์Œ ์•ž์„œ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ ์—ฌ๋Ÿฌ๋ถ„์˜ ๋‡Œ์™€ ๊ทผ์œก์„ ์œ„ํ•œ ์šด๋™์„ ํ•˜์„ธ์š”. -## ๐Ÿ’ป 3์ผ์ฐจ: ์‹ค์Šต +## ๐Ÿ’ป 3์ผ์ฐจ ์‹ค์Šต 1. ๋‚˜์ด๋ฅผ ์ •์ˆ˜ ๋ณ€์ˆ˜๋กœ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค. 2. ์ž์‹ ์˜ ํ‚ค๋ฅผ ํ”Œ๋กœํŠธ ๋ณ€์ˆ˜๋กœ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค. @@ -283,10 +283,10 @@ The perimeter of the triangle is 12 14. _๋‚˜๋Š” ์ด ๊ฐ•์ขŒ๊ฐ€ ์ „๋ฌธ์šฉ์–ด๋กœ ๊ฐ€๋“ํ•˜์ง€ ์•Š๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค. _in_ ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ _jargon_ ์ด ๋ฌธ์žฅ์— ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. 15. dragon๊ณผ python ๋ชจ๋‘ 'On'์ด ์—†์Šต๋‹ˆ๋‹ค. 16. _python_ ํ…์ŠคํŠธ์˜ ๊ธธ์ด๋ฅผ ์ฐพ์•„์„œ ๊ฐ’์„ float๋กœ ๋ณ€ํ™˜ํ•˜๊ณ  ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค. -17. ์ง์ˆ˜๋Š” 2๋กœ ๋‚˜๋ˆ„๊ณ  ๋‚˜๋จธ์ง€๋Š” 0์ž…๋‹ˆ๋‹ค. ํŒŒ์ด์ฌ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ˆซ์ž๊ฐ€ ์ง์ˆ˜์ธ์ง€ ์•„๋‹Œ์ง€ ์–ด๋–ป๊ฒŒ ํ™•์ธํ•ฉ๋‹ˆ๊นŒ? +17. ์ง์ˆ˜๋Š” 2๋กœ ๋‚˜๋ˆ„๊ณ  ๋‚˜๋จธ์ง€๋Š” 0์ž…๋‹ˆ๋‹ค. ํŒŒ์ด์ฌ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ˆซ์ž๊ฐ€ ์ง์ˆ˜์ธ์ง€ ์•„๋‹Œ์ง€ ์–ด๋–ป๊ฒŒ ํ™•์ธํ•˜๊ฒ ์Šต๋‹ˆ๊นŒ? 18. 7 x 3์˜ ๋‚˜๋ˆ—์…ˆ ๋ฒ„๋ฆผ์ด 2.7์˜ int ๋ณ€ํ™˜๊ฐ’๊ณผ ๋™์ผํ•œ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. 19. '10'์˜ ์œ ํ˜•์ด 10์˜ ์œ ํ˜•๊ณผ ๋™์ผํ•œ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. -20. if int('9)๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.8')๋Š” 10๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. +20. if int('9.8')์ด 10๊ณผ ๊ฐ™์€์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. 21. ์‚ฌ์šฉ์ž์—๊ฒŒ ์‹œ๊ฐ„ ๋ฐ ์‹œ๊ฐ„๋‹น ์š”๊ธˆ์„ ์ž…๋ ฅํ•˜๋„๋ก ์š”์ฒญํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ์‚ฌ๋žŒ์˜ ๊ธ‰์—ฌ๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๊นŒ? ```py From 2929ed04cd8a4aae68969846954e452f0ac6b2a8 Mon Sep 17 00:00:00 2001 From: jshyun1 Date: Fri, 9 Dec 2022 10:27:16 +0900 Subject: [PATCH 14/21] kor ver --- Korean/04_strings_ko.md | 591 ++++++++++++++++++++++++++++++++++++++++ Korean/readme_ko.md | 454 ++++++++++++++++++++++++++++++ 2 files changed, 1045 insertions(+) create mode 100644 Korean/04_strings_ko.md create mode 100644 Korean/readme_ko.md diff --git a/Korean/04_strings_ko.md b/Korean/04_strings_ko.md new file mode 100644 index 00000000..b2d92dee --- /dev/null +++ b/Korean/04_strings_ko.md @@ -0,0 +1,591 @@ +
+ 30 Days Of Python: Day 4 - Strings Twitter Follow +
+

Author: Asabeneh Yetayeh
Second Edition: July, 2021

+
+ +[<< Day 3](../03_Day_Operators/03_operators.md) | [Day 5 >>](../05_Day_Lists/05_lists.md) + +![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png) + +- [Day 4](#day-4) + - [๋ฌธ์ž์—ด](#strings) + - [๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ](#creating-a-string) + - [๋ฌธ์ž์—ด ์—ฐ๊ฒฐ](#string-concatenation) + - [๋ฌธ์ž์—ด์˜ ์ด์Šค์ผ€์ดํ”„ ์‹œํ€€์Šค](#escape-sequences-in-strings) + - [๋ฌธ์ž์—ด ํฌ๋งคํŒ…](#string-formatting) + - [์˜ฌ๋“œ ์Šคํƒ€์ผ ๋ฌธ์ž์—ด ํฌ๋งคํŒ…(% ์—ฐ์‚ฐ์ž)](#old-style-string-formatting--operator) + - [์ƒˆ๋กœ์šด ์Šคํƒ€์ผ ๋ฌธ์ž์—ด ํฌ๋งคํŒ…(str.format)](#new-style-string-formatting-strformat) + - [๋ฌธ์ž์—ด Interpolation / f-Strings (Python 3.6+)](#string-interpolation--f-strings-python-36) + - [๋ฌธ์ž ์‹œํ€€์Šค๋กœ์„œ์˜ Python ๋ฌธ์ž์—ด](#python-strings-as-sequences-of-characters) + - [์–ธํŒจํ‚น ๋ฌธ์ž](#unpacking-characters) + - [์ธ๋ฑ์Šค๋กœ ๋ฌธ์ž์—ด์˜ ๋ฌธ์ž์— ์•ก์„ธ์Šค](#accessing-characters-in-strings-by-index) + - [ํŒŒ์ด์ฌ ๋ฌธ์ž์—ด ์Šฌ๋ผ์ด์‹ฑ](#slicing-python-strings) + - [๋ฌธ์ž์—ด ๋ฆฌ๋ฒ„์Šค](#reversing-a-string) + - [์Šฌ๋ผ์ด์‹ฑํ•˜๋Š” ๋™์•ˆ ๋ฌธ์ž ๊ฑด๋„ˆ๋›ฐ๊ธฐ](#skipping-characters-while-slicing) + - [๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ](#string-methods) + - [๐Ÿ’ป Exercises - Day 4](#-exercises---day-4) + +# Day 4 + +## ๋ฌธ์ž์—ด + +ํ…์ŠคํŠธ๋Š” ๋ฌธ์ž์—ด ๋ฐ์ดํ„ฐ ์œ ํ˜•์ž…๋‹ˆ๋‹ค. ํ…์ŠคํŠธ๋กœ ์ž‘์„ฑ๋œ ๋ชจ๋“  ๋ฐ์ดํ„ฐ ์œ ํ˜•์€ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค. ์ž‘์€๋”ฐ์˜ดํ‘œ, ํฐ๋”ฐ์˜ดํ‘œ ๋˜๋Š” ์‚ผ์ค‘๋”ฐ์˜ดํ‘œ ์•„๋ž˜์˜ ๋ชจ๋“  ๋ฐ์ดํ„ฐ๋Š” ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ๋‹ค์–‘ํ•œ ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ์™€ ๋‚ด์žฅ ํ•จ์ˆ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋ฅผ ํ™•์ธํ•˜๋ ค๋ฉด len() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค. + +### ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ + +```py +letter = 'P' # A string could be a single character or a bunch of texts +print(letter) # P +print(len(letter)) # 1 +greeting = 'Hello, World!' # String could be made using a single or double quote,"Hello, World!" +print(greeting) # Hello, World! +print(len(greeting)) # 13 +sentence = "I hope you are enjoying 30 days of Python Challenge" +print(sentence) +``` + +์—ฌ๋Ÿฌ ์ค„ ๋ฌธ์ž์—ด์€ ์„ธ ๊ฐœ์˜ ์ž‘์€๋”ฐ์˜ดํ‘œ(''') ๋˜๋Š” ์„ธ ๊ฐœ์˜ ํฐ๋”ฐ์˜ดํ‘œ(""")๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ์˜ˆ๋ฅผ ์ฐธ์กฐํ•˜์‹ญ์‹œ์˜ค. + +```py +multiline_string = '''I am a teacher and enjoy teaching. +I didn't find anything as rewarding as empowering people. +That is why I created 30 days of python.''' +print(multiline_string) + +# Another way of doing the same thing +multiline_string = """I am a teacher and enjoy teaching. +I didn't find anything as rewarding as empowering people. +That is why I created 30 days of python.""" +print(multiline_string) +``` + +### ๋ฌธ์ž์—ด ์—ฐ๊ฒฐ + +๋ฌธ์ž์—ด์„ ํ•จ๊ป˜ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด์„ ๋ณ‘ํ•ฉํ•˜๊ฑฐ๋‚˜ ์—ฐ๊ฒฐํ•˜๋Š” ๊ฒƒ์„ ์—ฐ๊ฒฐ์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ์˜ˆ๋ฅผ ์ฐธ์กฐํ•˜์‹ญ์‹œ์˜ค. + +```py +first_name = 'Asabeneh' +last_name = 'Yetayeh' +space = ' ' +full_name = first_name + space + last_name +print(full_name) # Asabeneh Yetayeh +# Checking the length of a string using len() built-in function +print(len(first_name)) # 8 +print(len(last_name)) # 7 +print(len(first_name) > len(last_name)) # True +print(len(full_name)) # 16 +``` + +### ๋ฌธ์ž์—ด์˜ ์ด์Šค์ผ€์ดํ”„ ์‹œํ€€์Šค + +Python ๋ฐ ๊ธฐํƒ€ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์—์„œ \ ๋‹ค์Œ์— ์˜ค๋Š” ๋ฌธ์ž๋Š” ์ด์Šค์ผ€์ดํ”„ ์‹œํ€€์Šค์ž…๋‹ˆ๋‹ค. ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์ธ ์ด์Šค์ผ€์ดํ”„ ๋ฌธ์ž๋ฅผ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +- \n: ์ƒˆ๋กœ์šด ๋ผ์ธ +- \t: ํƒญ์€(8์นธ)์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. +- \\: ๋ฐฑ์Šฌ๋ž˜์‹œ +- \': ์ž‘์€๋”ฐ์˜ดํ‘œ(') +- \": ํฐ๋”ฐ์˜ดํ‘œ(") + +์ด์ œ ์œ„์˜ ์ด์Šค์ผ€์ดํ”„ ์‹œํ€€์Šค๋ฅผ ์˜ˆ์ œ์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +```py +print('I hope everyone is enjoying the Python Challenge.\nAre you ?') # line break +print('Days\tTopics\tExercises') # adding tab space or 4 spaces +print('Day 1\t3\t5') +print('Day 2\t3\t5') +print('Day 3\t3\t5') +print('Day 4\t3\t5') +print('This is a backslash symbol (\\)') # To write a backslash +print('In every programming language it starts with \"Hello, World!\"') # to write a double quote inside a single quote + +# output +I hope every one is enjoying the Python Challenge. +Are you ? +Days Topics Exercises +Day 1 5 5 +Day 2 6 20 +Day 3 5 23 +Day 4 1 35 +This is a backslash symbol (\) +In every programming language it starts with "Hello, World!" +``` + +### ๋ฌธ์ž์—ด ํฌ๋งคํŒ… + +#### ์˜ฌ๋“œ ์Šคํƒ€์ผ ๋ฌธ์ž์—ด ํ˜•์‹ํ™”(% ์—ฐ์‚ฐ์ž) + +Python์—๋Š” ๋ฌธ์ž์—ด ํ˜•์‹์„ ์ง€์ •ํ•˜๋Š” ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ์„น์…˜์—์„œ๋Š” ๊ทธ ์ค‘ ์ผ๋ถ€๋ฅผ ๋‹ค๋ฃฐ ๊ฒƒ์ž…๋‹ˆ๋‹ค. "%" ์—ฐ์‚ฐ์ž๋Š” "์ธ์ˆ˜ ์ง€์ •์ž", "%s"์™€ ๊ฐ™์€ ํŠน์ˆ˜ ๊ธฐํ˜ธ์™€ ํ•จ๊ป˜ ์ผ๋ฐ˜ ํ…์ŠคํŠธ๋ฅผ ํฌํ•จํ•˜๋Š” ํ˜•์‹ ๋ฌธ์ž์—ด๊ณผ ํ•จ๊ป˜ "ํŠœํ”Œ"(๊ณ ์ • ํฌ๊ธฐ ๋ชฉ๋ก)๋กœ ๋ฌถ์ธ ๋ณ€์ˆ˜ ์„ธํŠธ์˜ ํ˜•์‹์„ ์ง€์ •ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. , "%d", "%f", "%. ์ž๋ฆฟ์ˆ˜ f". + +- %s - ๋ฌธ์ž์—ด(๋˜๋Š” ์ˆซ์ž์™€ ๊ฐ™์€ ๋ฌธ์ž์—ด ํ‘œํ˜„์ด ์žˆ๋Š” ๋ชจ๋“  ๊ฐ์ฒด) +- %d - ์ •์ˆ˜ +- %f - ๋ถ€๋™ ์†Œ์ˆ˜์  ์ˆซ์ž +- "%. number of digits f" - ์ •๋ฐ€๋„๊ฐ€ ๊ณ ์ •๋œ ๋ถ€๋™ ์†Œ์ˆ˜์  ์ˆซ์ž + +```py +# Strings only +first_name = 'Asabeneh' +last_name = 'Yetayeh' +language = 'Python' +formated_string = 'I am %s %s. I teach %s' %(first_name, last_name, language) +print(formated_string) + +# Strings and numbers +radius = 10 +pi = 3.14 +area = pi * radius ** 2 +formated_string = 'The area of circle with a radius %d is %.2f.' %(radius, area) # 2 refers the 2 significant digits after the point + +python_libraries = ['Django', 'Flask', 'NumPy', 'Matplotlib','Pandas'] +formated_string = 'The following are python libraries:%s' % (python_libraries) +print(formated_string) # "The following are python libraries:['Django', 'Flask', 'NumPy', 'Matplotlib','Pandas']" +``` + +#### ์ƒˆ๋กœ์šด์Šคํƒ€์ผ ๋ฌธ์ž์—ด ํ˜•์‹ํ™”(str.format) + +์ด ํ˜•์‹์€ Python ๋ฒ„์ „ 3์—์„œ ๋„์ž…๋˜์—ˆ์Šต๋‹ˆ๋‹ค. + +```py + +first_name = 'Asabeneh' +last_name = 'Yetayeh' +language = 'Python' +formated_string = 'I am {} {}. I teach {}'.format(first_name, last_name, language) +print(formated_string) +a = 4 +b = 3 + +print('{} + {} = {}'.format(a, b, a + b)) +print('{} - {} = {}'.format(a, b, a - b)) +print('{} * {} = {}'.format(a, b, a * b)) +print('{} / {} = {:.2f}'.format(a, b, a / b)) # limits it to two digits after decimal +print('{} % {} = {}'.format(a, b, a % b)) +print('{} // {} = {}'.format(a, b, a // b)) +print('{} ** {} = {}'.format(a, b, a ** b)) + +# output +4 + 3 = 7 +4 - 3 = 1 +4 * 3 = 12 +4 / 3 = 1.33 +4 % 3 = 1 +4 // 3 = 1 +4 ** 3 = 64 + +# Strings and numbers +radius = 10 +pi = 3.14 +area = pi * radius ** 2 +formated_string = 'The area of a circle with a radius {} is {:.2f}.'.format(radius, area) # 2 digits after decimal +print(formated_string) + +``` + +#### ๋ฌธ์ž์—ด Interpolation / f-Strings (Python 3.6+) + +๋˜ ๋‹ค๋ฅธ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด ํ˜•์‹ํ™”๋Š” ๋ฌธ์ž์—ด ๋ณด๊ฐ„๋ฒ•์ธ f-๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด์€ f๋กœ ์‹œ์ž‘ํ•˜๊ณ  ํ•ด๋‹น ์œ„์น˜์— ๋ฐ์ดํ„ฐ๋ฅผ ์ฃผ์ž…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +```py +a = 4 +b = 3 +print(f'{a} + {b} = {a +b}') +print(f'{a} - {b} = {a - b}') +print(f'{a} * {b} = {a * b}') +print(f'{a} / {b} = {a / b:.2f}') +print(f'{a} % {b} = {a % b}') +print(f'{a} // {b} = {a // b}') +print(f'{a} ** {b} = {a ** b}') +``` + +### ๋ฌธ์ž ์‹œํ€€์Šค๋กœ์„œ์˜ Python ๋ฌธ์ž์—ด + +Python ๋ฌธ์ž์—ด์€ ๋ฌธ์ž ์‹œํ€€์Šค์ด๋ฉฐ, ๊ธฐ๋ณธ ์•ก์„ธ์Šค ๋ฐฉ๋ฒ•์„ ๋‹ค๋ฅธ Python ์ˆœ์„œ ๊ฐ์ฒด ์‹œํ€€์Šค(๋ชฉ๋ก ๋ฐ ํŠœํ”Œ)์™€ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด(๋ฐ ๋ชจ๋“  ์‹œํ€€์Šค์˜ ๊ฐœ๋ณ„ ๋ฉค๋ฒ„)์—์„œ ๋‹จ์ผ ๋ฌธ์ž๋ฅผ ์ถ”์ถœํ•˜๋Š” ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•์€ ํ•ด๋‹น ๋ณ€์ˆ˜๋กœ ์••์ถ•์„ ํ‘ธ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. + +#### ์–ธํŒจํ‚น ๋ฌธ์ž + +``` +language = 'Python' +a,b,c,d,e,f = language # unpacking sequence characters into variables +print(a) # P +print(b) # y +print(c) # t +print(d) # h +print(e) # o +print(f) # n +``` + +#### ์ธ๋ฑ์Šค๋กœ ๋ฌธ์ž์—ด์˜ ๋ฌธ์ž์— ์•ก์„ธ์Šค + +ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ์นด์šดํŒ…์€ 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋ฌธ์ž์—ด์˜ ์ฒซ ๋ฒˆ์งธ ๋ฌธ์ž๋Š” ์ธ๋ฑ์Šค๊ฐ€ 0์ด๊ณ  ๋ฌธ์ž์—ด์˜ ๋งˆ์ง€๋ง‰ ๋ฌธ์ž๋Š” ๋ฌธ์ž์—ด์˜ ๊ธธ์ด์—์„œ 1์„ ๋บ€ ๊ฐ’์ž…๋‹ˆ๋‹ค. + +![String index](../images/string_index.png) + +```py +language = 'Python' +first_letter = language[0] +print(first_letter) # P +second_letter = language[1] +print(second_letter) # y +last_index = len(language) - 1 +last_letter = language[last_index] +print(last_letter) # n +``` + +์˜ค๋ฅธ์ชฝ ๋์—์„œ ์‹œ์ž‘ํ•˜๋ ค๋ฉด ์Œ์ˆ˜ ์ธ๋ฑ์‹ฑ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. -1์€ ๋งˆ์ง€๋ง‰ ์ธ๋ฑ์Šค์ž…๋‹ˆ๋‹ค. + +```py +language = 'Python' +last_letter = language[-1] +print(last_letter) # n +second_last = language[-2] +print(second_last) # o +``` + +#### ํŒŒ์ด์ฌ ๋ฌธ์ž์—ด ์Šฌ๋ผ์ด์‹ฑ + +ํŒŒ์ด์ฌ์—์„œ๋Š” ๋ฌธ์ž์—ด์„ ํ•˜์œ„ ๋ฌธ์ž์—ด๋กœ ์Šฌ๋ผ์ด์Šคํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +```py +language = 'Python' +first_three = language[0:3] # starts at zero index and up to 3 but not include 3 +print(first_three) #Pyt +last_three = language[3:6] +print(last_three) # hon +# Another way +last_three = language[-3:] +print(last_three) # hon +last_three = language[3:] +print(last_three) # hon +``` + +#### ๋ฌธ์ž์—ด ๋ฆฌ๋ฒ„์Šค + +ํŒŒ์ด์ฌ์—์„œ ๋ฌธ์ž์—ด์„ ์‰ฝ๊ฒŒ ๋’ค์ง‘์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +```py +greeting = 'Hello, World!' +print(greeting[::-1]) # !dlroW ,olleH +``` + +#### ์Šฌ๋ผ์ด์‹ฑํ•˜๋Š” ๋™์•ˆ ๋ฌธ์ž ๊ฑด๋„ˆ๋›ฐ๊ธฐ + +์Šฌ๋ผ์ด์Šค ๋ฉ”์†Œ๋“œ์— ๋‹จ๊ณ„ ์ธ์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜์—ฌ ์Šฌ๋ผ์ด์Šคํ•˜๋Š” ๋™์•ˆ ๋ฌธ์ž๋ฅผ ๊ฑด๋„ˆ๋›ธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +```py +language = 'Python' +pto = language[0:6:2] # +print(pto) # Pto +``` + +### ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ + +๋ฌธ์ž์—ด์„ ํ˜•์‹ํ™”ํ•  ์ˆ˜ ์žˆ๋Š” ๋งŽ์€ ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ์˜ˆ์ œ์—์„œ ์ผ๋ถ€ ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ๋ฅผ ์ฐธ์กฐํ•˜์‹ญ์‹œ์˜ค. + +- capitalize(): ๋ฌธ์ž์—ด์˜ ์ฒซ ๋ฒˆ์งธ ๋ฌธ์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜ + +```py +challenge = 'thirty days of python' +print(challenge.capitalize()) # 'Thirty days of python' +``` + +- count(): ๋ฌธ์ž์—ด์—์„œ ํ•˜์œ„ ๋ฌธ์ž์—ด์˜ ๋ฐœ์ƒ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. count(substring, start=.., end=..). ์‹œ์ž‘์€ ์นด์šดํŠธ๋ฅผ ์œ„ํ•œ ์‹œ์ž‘ ์ธ๋ฑ์‹ฑ์ด๊ณ  ๋์€ ์นด์šดํŠธํ•  ๋งˆ์ง€๋ง‰ ์ธ๋ฑ์Šค์ž…๋‹ˆ๋‹ค. + +```py +challenge = 'thirty days of python' +print(challenge.count('y')) # 3 +print(challenge.count('y', 7, 14)) # 1, +print(challenge.count('th')) # 2` +``` + +- endswith(): ๋ฌธ์ž์—ด์ด ์ง€์ •๋œ ๋์œผ๋กœ ๋๋‚˜๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. + +```py +challenge = 'thirty days of python' +print(challenge.endswith('on')) # True +print(challenge.endswith('tion')) # False +``` + +- expandtabs(): ํƒญ ๋ฌธ์ž๋ฅผ ๊ณต๋ฐฑ์œผ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค. ๊ธฐ๋ณธ ํƒญ ํฌ๊ธฐ๋Š” 8์ž…๋‹ˆ๋‹ค. ํƒญ ํฌ๊ธฐ ์ธ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +```py +challenge = 'thirty\tdays\tof\tpython' +print(challenge.expandtabs()) # 'thirty days of python' +print(challenge.expandtabs(10)) # 'thirty days of python' +``` + +- find(): ํ•˜์œ„ ๋ฌธ์ž์—ด์ด ์ฒ˜์Œ ๋‚˜ํƒ€๋‚˜๋Š” ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ฐพ์„ ์ˆ˜ ์—†์œผ๋ฉด -1์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. + +```py +challenge = 'thirty days of python' +print(challenge.count('y')) # 3 +print(challenge.count('y', 7, 14)) # 1, +print(challenge.count('th')) # 2` +``` + +- rfind(): ํ•˜์œ„ ๋ฌธ์ž์—ด์ด ๋งˆ์ง€๋ง‰์œผ๋กœ ๋‚˜ํƒ€๋‚˜๋Š” ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ฐพ์„ ์ˆ˜ ์—†์œผ๋ฉด -1์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. + +```py +challenge = 'thirty days of python' +print(challenge.rfind('y')) # 5 +print(challenge.rfind('th')) # 1 +``` + +- format(): ๋ฌธ์ž์—ด์„ ๋” ๋‚˜์€ ์ถœ๋ ฅ์œผ๋กœ ํฌ๋งทํ•ฉ๋‹ˆ๋‹ค.
๋ฌธ์ž์—ด ํ˜•์‹์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ด [๋งํฌ](https://www.programiz.com/python-programming/methods/string/format) ๋ฅผ ํ™•์ธํ•˜์„ธ์š”. + +```py +first_name = 'Asabeneh' +last_name = 'Yetayeh' +age = 250 +job = 'teacher' +country = 'Finland' +sentence = 'I am {} {}. I am a {}. I am {} years old. I live in {}.'.format(first_name, last_name, age, job, country) +print(sentence) # I am Asabeneh Yetayeh. I am 250 years old. I am a teacher. I live in Finland. + +radius = 10 +pi = 3.14 +area = pi * radius ** 2 +result = 'The area of a circle with radius {} is {}'.format(str(radius), str(area)) +print(result) # The area of a circle with radius 10 is 314 +``` + +- index(): ํ•˜์œ„ ๋ฌธ์ž์—ด์˜ ๊ฐ€์žฅ ๋‚ฎ์€ ์ƒ‰์ธ์„ ๋ฐ˜ํ™˜ํ•˜๊ณ  ์ถ”๊ฐ€ ์ธ์ˆ˜๋Š” ์‹œ์ž‘ ๋ฐ ๋ ์ƒ‰์ธ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค(๊ธฐ๋ณธ๊ฐ’ 0 ๋ฐ ๋ฌธ์ž์—ด ๊ธธ์ด - 1). ํ•˜์œ„ ๋ฌธ์ž์—ด์„ ์ฐพ์„ ์ˆ˜ ์—†์œผ๋ฉด valueError๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. + +```py +challenge = 'thirty days of python' +sub_string = 'da' +print(challenge.index(sub_string)) # 7 +print(challenge.index(sub_string, 9)) # error +``` + +- rindex(): ํ•˜์œ„ ๋ฌธ์ž์—ด์˜ ๊ฐ€์žฅ ๋†’์€ ์ƒ‰์ธ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ถ”๊ฐ€ ์ธ์ˆ˜๋Š” ์‹œ์ž‘ ๋ฐ ๋ ์ƒ‰์ธ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค(๊ธฐ๋ณธ๊ฐ’ 0 ๋ฐ ๋ฌธ์ž์—ด ๊ธธ์ด - 1). + +```py +challenge = 'thirty days of python' +sub_string = 'da' +print(challenge.rindex(sub_string)) # 8 +print(challenge.rindex(sub_string, 9)) # error +``` + +- isalnum(): ์˜์ˆซ์ž ํ™•์ธ + +```py +challenge = 'ThirtyDaysPython' +print(challenge.isalnum()) # True + +challenge = '30DaysPython' +print(challenge.isalnum()) # True + +challenge = 'thirty days of python' +print(challenge.isalnum()) # False, space is not an alphanumeric character + +challenge = 'thirty days of python 2019' +print(challenge.isalnum()) # False +``` + +- isalpha(): ๋ชจ๋“  ๋ฌธ์ž์—ด ์š”์†Œ๊ฐ€ ์•ŒํŒŒ๋ฒณ ๋ฌธ์ž(az ๋ฐ AZ)์ธ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. + +```py +challenge = 'thirty days of python' +print(challenge.isalpha()) # False, space is once again excluded +challenge = 'ThirtyDaysPython' +print(challenge.isalpha()) # True +num = '123' +print(num.isalpha()) # False +``` + +- isdecimal(): ๋ฌธ์ž์—ด์˜ ๋ชจ๋“  ๋ฌธ์ž๊ฐ€ ์‹ญ์ง„์ˆ˜(0-9)์ธ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. + +```py +challenge = 'thirty days of python' +print(challenge.isdecimal()) # False +challenge = '123' +print(challenge.isdecimal()) # True +challenge = '\u00B2' +print(challenge.isdigit()) # False +challenge = '12 3' +print(challenge.isdecimal()) # False, space not allowed +``` + +- isdigit(): ๋ฌธ์ž์—ด์˜ ๋ชจ๋“  ๋ฌธ์ž๊ฐ€ ์ˆซ์ž์ธ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค(์ˆซ์ž๋Š” 0-9 ๋ฐ ์ผ๋ถ€ ๋‹ค๋ฅธ ์œ ๋‹ˆ์ฝ”๋“œ ๋ฌธ์ž). + +```py +challenge = 'Thirty' +print(challenge.isdigit()) # False +challenge = '30' +print(challenge.isdigit()) # True +challenge = '\u00B2' +print(challenge.isdigit()) # True +``` + +- isnumeric(): ๋ฌธ์ž์—ด์˜ ๋ชจ๋“  ๋ฌธ์ž๊ฐ€ ์ˆซ์ž์ธ์ง€ ๋˜๋Š” ์ˆซ์ž์™€ ๊ด€๋ จ๋œ ๊ฒƒ์ธ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค(isdigit()์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ยฝ๊ณผ ๊ฐ™์€ ๋” ๋งŽ์€ ๊ธฐํ˜ธ๋ฅผ ํ—ˆ์šฉํ•ฉ๋‹ˆ๋‹ค). + +```py +num = '10' +print(num.isnumeric()) # True +num = '\u00BD' # ยฝ +print(num.isnumeric()) # True +num = '10.5' +print(num.isnumeric()) # False +``` + +- isidentifier(): ์œ ํšจํ•œ ์‹๋ณ„์ž๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด์ด ์œ ํšจํ•œ ๋ณ€์ˆ˜ ์ด๋ฆ„์ธ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. + +```py +challenge = '30DaysOfPython' +print(challenge.isidentifier()) # False, because it starts with a number +challenge = 'thirty_days_of_python' +print(challenge.isidentifier()) # True +``` + +- islower(): ๋ฌธ์ž์—ด์˜ ๋ชจ๋“  ์•ŒํŒŒ๋ฒณ ๋ฌธ์ž๊ฐ€ ์†Œ๋ฌธ์ž์ธ์ง€ ํ™•์ธ + +```py +challenge = 'thirty days of python' +print(challenge.islower()) # True +challenge = 'Thirty days of python' +print(challenge.islower()) # False +``` + +- islower(): ๋ฌธ์ž์—ด์˜ ๋ชจ๋“  ์•ŒํŒŒ๋ฒณ ๋ฌธ์ž๊ฐ€ ์†Œ๋ฌธ์ž์ธ์ง€ ํ™•์ธ + +```py +challenge = 'thirty days of python' +print(challenge.isupper()) # False +challenge = 'THIRTY DAYS OF PYTHON' +print(challenge.isupper()) # True +``` + +- join(): ์—ฐ๊ฒฐ๋œ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. + +```py +web_tech = ['HTML', 'CSS', 'JavaScript', 'React'] +result = ' '.join(web_tech) +print(result) # 'HTML CSS JavaScript React' +``` + +```py +web_tech = ['HTML', 'CSS', 'JavaScript', 'React'] +result = '# '.join(web_tech) +print(result) # 'HTML# CSS# JavaScript# React' +``` + +- strip(): ๋ฌธ์ž์—ด์˜ ์‹œ์ž‘๊ณผ ๋์—์„œ ์‹œ์ž‘ํ•˜์—ฌ ์ฃผ์–ด์ง„ ๋ชจ๋“  ๋ฌธ์ž๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค. + +```py +challenge = 'thirty days of pythoonnn' +print(challenge.strip('noth')) # 'irty days of py' +``` + +- replace(): ํ•˜์œ„ ๋ฌธ์ž์—ด์„ ์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด๋กœ ๋Œ€์ฒดํ•ฉ๋‹ˆ๋‹ค. + +```py +challenge = 'thirty days of python' +print(challenge.replace('python', 'coding')) # 'thirty days of coding' +``` + +- split(): ์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด ๋˜๋Š” ๊ณต๋ฐฑ์„ ๊ตฌ๋ถ„ ๊ธฐํ˜ธ๋กœ ์‚ฌ์šฉํ•˜์—ฌ ๋ฌธ์ž์—ด์„ ๋ถ„ํ• ํ•ฉ๋‹ˆ๋‹ค. + +```py +challenge = 'thirty days of python' +print(challenge.split()) # ['thirty', 'days', 'of', 'python'] +challenge = 'thirty, days, of, python' +print(challenge.split(', ')) # ['thirty', 'days', 'of', 'python'] +``` + +- title(): ์ œ๋ชฉ ์ผ€์ด์Šค ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. + +```py +challenge = 'thirty days of python' +print(challenge.title()) # Thirty Days Of Python +``` + +- swapcase(): ๋ชจ๋“  ๋Œ€๋ฌธ์ž๋ฅผ ์†Œ๋ฌธ์ž๋กœ, ๋ชจ๋“  ์†Œ๋ฌธ์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜ + +```py +challenge = 'thirty days of python' +print(challenge.swapcase()) # THIRTY DAYS OF PYTHON +challenge = 'Thirty Days Of Python' +print(challenge.swapcase()) # tHIRTY dAYS oF pYTHON +``` + +- startswith(): ๋ฌธ์ž์—ด์ด ์ง€์ •๋œ ๋ฌธ์ž์—ด๋กœ ์‹œ์ž‘ํ•˜๋Š”์ง€ ํ™•์ธ + +```py +challenge = 'thirty days of python' +print(challenge.startswith('thirty')) # True + +challenge = '30 days of python' +print(challenge.startswith('thirty')) # False +``` + +๐ŸŒ• ๋‹น์‹ ์€ ํŠน๋ณ„ํ•œ ์‚ฌ๋žŒ์ด๊ณ  ๋†€๋ผ์šด ์ž ์žฌ๋ ฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹น์‹ ์€ ๋ฐฉ๊ธˆ 4์ผ ์ฐจ ๋„์ „์„ ์™„๋ฃŒํ–ˆ๊ณ  ๋‹น์‹ ์€ ์œ„๋Œ€ํ•จ์„ ํ–ฅํ•œ ๋‹น์‹ ์˜ ๊ธธ์— 4๊ฑธ์Œ ๋‚จ์•˜์Šต๋‹ˆ๋‹ค. ์ด์ œ ๋‡Œ์™€ ๊ทผ์œก์„ ์œ„ํ•œ ๋ช‡ ๊ฐ€์ง€ ํ›ˆ๋ จ์„ ํ•˜์‹ญ์‹œ์˜ค. + +## ๐Ÿ’ป Exercises - Day 4 + +1. ๋ฌธ์ž์—ด 'Thirty', 'Days', 'Of', 'Python'์„ ๋‹จ์ผ ๋ฌธ์ž์—ด 'Thirty Days Of Python'์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค. +2. ๋ฌธ์ž์—ด 'Coding', 'For' , 'All'์„ ๋‹จ์ผ ๋ฌธ์ž์—ด 'Coding For All'์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค. +3. company๋ผ๋Š” ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ์ดˆ๊ธฐ ๊ฐ’ "Coding For All"์— ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. +4. *print()* ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํšŒ์‚ฌ ๋ณ€์ˆ˜๋ฅผ ์ธ์‡„ํ•ฉ๋‹ˆ๋‹ค. +5. *len()* ๋ฉ”์„œ๋“œ์™€ *print()* ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํšŒ์‚ฌ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋ฅผ ์ธ์‡„ํ•ฉ๋‹ˆ๋‹ค. +6. *upper()* ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋“  ๋ฌธ์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค. +7. *lower()* ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋“  ๋ฌธ์ž๋ฅผ ์†Œ๋ฌธ์ž๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค. +8. ๋ฌธ์ž์—ด *Coding For All* ์˜ ๊ฐ’์„ ํ˜•์‹ํ™”ํ•˜๋ ค๋ฉด capitalize(), title(), swapcase() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค. +9. *Coding For All* ๋ฌธ์ž์—ด์˜ ์ฒซ ๋ฒˆ์งธ ๋‹จ์–ด๋ฅผ ์ž˜๋ผ๋ƒ…๋‹ˆ๋‹ค. +10. Index, find ๋˜๋Š” ๊ธฐํƒ€ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜์—ฌ *Coding For All* ๋ฌธ์ž์—ด์— ๋‹จ์–ด Coding์ด ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. +11. ๋ฌธ์ž์—ด 'Coding For All'์˜ ์ฝ”๋”ฉ์ด๋ผ๋Š” ๋‹จ์–ด๋ฅผ Python์œผ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค. +12. replace ๋ฉ”์„œ๋“œ ๋˜๋Š” ๊ธฐํƒ€ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋‘๋ฅผ ์œ„ํ•œ Python์„ ๋ชจ๋‘๋ฅผ ์œ„ํ•œ Python์œผ๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค. +13. ๊ณต๋ฐฑ์„ ๊ตฌ๋ถ„ ๊ธฐํ˜ธ๋กœ ์‚ฌ์šฉํ•˜์—ฌ ๋ฌธ์ž์—ด 'Coding For All'์„ ๋ถ„ํ• ํ•ฉ๋‹ˆ๋‹ค(split()). +14. "Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon"์€ ์‰ผํ‘œ์—์„œ ๋ฌธ์ž์—ด์„ ๋‚˜๋ˆ•๋‹ˆ๋‹ค. +15. ๋ฌธ์ž์—ด *Coding For All* ์—์„œ ์ธ๋ฑ์Šค 0์— ์žˆ๋Š” ๋ฌธ์ž๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ? +16. ๋ฌธ์ž์—ด *Coding For All* ์—์„œ ์ธ๋ฑ์Šค 0์— ์žˆ๋Š” ๋ฌธ์ž๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ? +17. "Coding For All" ๋ฌธ์ž์—ด์—์„œ ์ธ๋ฑ์Šค 10์— ์žˆ๋Š” ๋ฌธ์ž๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ? +18. 'Python For Everyone'์ด๋ผ๋Š” ์ด๋ฆ„์˜ ์•ฝ์–ด ๋˜๋Š” ์•ฝ์–ด๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. +19. 'Coding For All'์ด๋ผ๋Š” ์ด๋ฆ„์˜ ์•ฝ์–ด ๋˜๋Š” ์•ฝ์–ด๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. +20. Index๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Coding For All์—์„œ C๊ฐ€ ์ฒ˜์Œ ๋‚˜ํƒ€๋‚˜๋Š” ์œ„์น˜๋ฅผ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค. +21. Index๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Coding For All์—์„œ F๊ฐ€ ์ฒ˜์Œ ๋‚˜ํƒ€๋‚˜๋Š” ์œ„์น˜๋ฅผ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค. +22. Coding For All People์—์„œ l์ด ๋งˆ์ง€๋ง‰์œผ๋กœ ๋‚˜ํƒ€๋‚˜๋Š” ์œ„์น˜๋ฅผ ๊ฒฐ์ •ํ•˜๋ ค๋ฉด rfind๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค. +23. ์ƒ‰์ธ ๋˜๋Š” ์ฐพ๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์Œ ๋ฌธ์žฅ์—์„œ 'because'๋ผ๋Š” ๋‹จ์–ด๊ฐ€ ์ฒ˜์Œ ๋‚˜ํƒ€๋‚˜๋Š” ์œ„์น˜๋ฅผ ์ฐพ์Šต๋‹ˆ๋‹ค. +24. ์ƒ‰์ธ ๋˜๋Š” ์ฐพ๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์Œ ๋ฌธ์žฅ์—์„œ 'because'๋ผ๋Š” ๋‹จ์–ด๊ฐ€ ์ฒ˜์Œ ๋‚˜ํƒ€๋‚˜๋Š” ์œ„์น˜๋ฅผ ์ฐพ์Šต๋‹ˆ๋‹ค. +25. ์ƒ‰์ธ ๋˜๋Š” ์ฐพ๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์Œ ๋ฌธ์žฅ์—์„œ 'because'๋ผ๋Š” ๋‹จ์–ด๊ฐ€ ์ฒ˜์Œ ๋‚˜ํƒ€๋‚˜๋Š” ์œ„์น˜๋ฅผ ์ฐพ์Šต๋‹ˆ๋‹ค. +26. ์ƒ‰์ธ ๋˜๋Š” ์ฐพ๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์Œ ๋ฌธ์žฅ์—์„œ 'because'๋ผ๋Š” ๋‹จ์–ด๊ฐ€ ์ฒ˜์Œ ๋‚˜ํƒ€๋‚˜๋Š” ์œ„์น˜๋ฅผ ์ฐพ์Šต๋‹ˆ๋‹ค. +27. ๋‹ค์Œ ๋ฌธ์žฅ์—์„œ 'because because because'๋ผ๋Š” ๊ตฌ๋ฌธ์„ ์ž˜๋ผ๋ƒ…๋‹ˆ๋‹ค. +28. 'Coding For All'์€ ํ•˜์œ„ ๋ฌธ์ž์—ด *Coding* ์œผ๋กœ ์‹œ์ž‘ํ•ฉ๋‹ˆ๊นŒ? +29. 'Coding For All'์€ ํ•˜์œ„ ๋ฌธ์ž์—ด *์ฝ”๋”ฉ* ์œผ๋กœ ๋๋‚ฉ๋‹ˆ๊นŒ? +30. ' Coding For All ' , ์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด์—์„œ ์™ผ์ชฝ ๋ฐ ์˜ค๋ฅธ์ชฝ ํ›„ํ–‰ ๊ณต๋ฐฑ์„ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค. +31. ๋‹ค์Œ ๋ณ€์ˆ˜ ์ค‘ isidentifier() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ True๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ณ€์ˆ˜๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ? + - 30DaysOfPython + - thirty_days_of_python +32. ๋‹ค์Œ ๋ชฉ๋ก์—๋Š” ์ผ๋ถ€ ํŒŒ์ด์ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ด๋ฆ„์ด ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค: ['Django', 'Flask', 'Bottle', 'Pyramid', 'Falcon']. ๊ณต๋ฐฑ ๋ฌธ์ž์—ด์ด ์žˆ๋Š” ํ•ด์‹œ๋กœ ๋ชฉ๋ก์— ๊ฐ€์ž…ํ•˜์‹ญ์‹œ์˜ค. +33. ์ƒˆ ์ค„ ์ด์Šค์ผ€์ดํ”„ ์‹œํ€€์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์Œ ๋ฌธ์žฅ์„ ๊ตฌ๋ถ„ํ•ฉ๋‹ˆ๋‹ค. + ```py + I am enjoying this challenge. + I just wonder what is next. + ``` +34. ์ƒˆ ์ค„ ์ด์Šค์ผ€์ดํ”„ ์‹œํ€€์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์Œ ๋ฌธ์žฅ์„ ๊ตฌ๋ถ„ํ•ฉ๋‹ˆ๋‹ค. + ```py + Name Age Country City + Asabeneh 250 Finland Helsinki + ``` +35. ๋ฌธ์ž์—ด ํ˜•์‹ ์ง€์ • ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์Œ์„ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค: + +```sh +radius = 10 +area = 3.14 * radius ** 2 +The area of a circle with radius 10 is 314 meters square. +``` + +1. ๋ฌธ์ž์—ด ํ˜•์‹ํ™” ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์Œ์„ ์ž‘์„ฑํ•˜์‹ญ์‹œ์˜ค: + +```sh +8 + 6 = 14 +8 - 6 = 2 +8 * 6 = 48 +8 / 6 = 1.33 +8 % 6 = 2 +8 // 6 = 1 +8 ** 6 = 262144 +``` + +๐ŸŽ‰ ์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค! ๐ŸŽ‰ + +[<< Day 3](../03_Day_Operators/03_operators.md) | [Day 5 >>](../05_Day_Lists/05_lists.md) diff --git a/Korean/readme_ko.md b/Korean/readme_ko.md new file mode 100644 index 00000000..bc628609 --- /dev/null +++ b/Korean/readme_ko.md @@ -0,0 +1,454 @@ +# ๐Ÿ 30 Days Of Python + +|# Day | Topics | +|------|:---------------------------------------------------------:| +| 01 | [Introduction](./readme_ko.md)| +| 02 | [Variables, Built-in Functions](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md)| +| 03 | [Operators](../03_Day_Operators/03_operators.md)| +| 04 | [Strings](../04_Day_Strings/04_strings.md)| +| 05 | [Lists](../05_Day_Lists/05_lists.md)| +| 06 | [Tuples](../06_Day_Tuples/06_tuples.md)| +| 07 | [Sets](../07_Day_Sets/07_sets.md)| +| 08 | [Dictionaries](../08_Day_Dictionaries/08_dictionaries.md)| +| 09 | [Conditionals](../09_Day_Conditionals/09_conditionals.md)| +| 10 | [Loops](../10_Day_Loops/10_loops.md)| +| 11 | [Functions](../11_Day_Functions/11_functions.md)| +| 12 | [Modules](../12_Day_Modules/12_modules.md)| +| 13 | [List Comprehension](../13_Day_List_comprehension/13_list_comprehension.md)| +| 14 | [Higher Order Functions](../14_Day_Higher_order_functions/14_higher_order_functions.md)| +| 15 | [Python Type Errors](../15_Day_Python_type_errors/15_python_type_errors.md)| +| 16 | [Python Date time](../16_Day_Python_date_time/16_python_datetime.md) | +| 17 | [Exception Handling](../17_Day_Exception_handling/17_exception_handling.md)| +| 18 | [Regular Expressions](../18_Day_Regular_expressions/18_regular_expressions.md)| +| 19 | [File Handling](../19_Day_File_handling/19_file_handling.md)| +| 20 | [Python Package Manager](../20_Day_Python_package_manager/20_python_package_manager.md)| +| 21 | [Classes and Objects](../21_Day_Classes_and_objects/21_classes_and_objects.md)| +| 22 | [Web Scraping](../22_Day_Web_scraping/22_web_scraping.md)| +| 23 | [Virtual Environment](../23_Day_Virtual_environment/23_virtual_environment.md)| +| 24 | [Statistics](../24_Day_Statistics/24_statistics.md)| +| 25 | [Pandas](../25_Day_Pandas/25_pandas.md)| +| 26 | [Python web](../26_Day_Python_web/26_python_web.md)| +| 27 | [Python with MongoDB](../27_Day_Python_with_mongodb/27_python_with_mongodb.md)| +| 28 | [API](../28_Day_API/28_API.md)| +| 29 | [Building API](../29_Day_Building_API/29_building_API.md)| +| 30 | [Conclusions](../30_Day_Conclusions/30_conclusions.md)| + +๐Ÿงก๐Ÿงก๐Ÿงก HAPPY CODING ๐Ÿงก๐Ÿงก๐Ÿงก + +
+Support the author to create more educational materials
+Paypal Logo +
+ +
+

30 Days Of Python: Day 1 - Introduction

+ + + + + Twitter Follow + + + Author: + Asabeneh Yetayeh
+ Second Edition: July, 2021 +
+
+ + +[Day 2 >>](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) + +![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png) + +- [๐Ÿ 30 Days Of Python](#-30-days-of-python) +- [๐Ÿ“˜ Day 1](#-day-1) + - [ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค](#ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค) + - [์†Œ๊ฐœ](#์†Œ๊ฐœ) + - [์™œ Python์ด๋Š๋ƒ?](#์™œ-python์ด๋Š๋ƒ?) + - [ํ™˜๊ฒฝ ์„ค์ •](#ํ™˜๊ฒฝ-์„ค์ •) + - [Python ์„ค์น˜](#python-์„ค์น˜) + - [Python ์…ธ](#python-์…ธ) + - [Visual Studio Code ์„ค์น˜](#visual-studio-code-์„ค์น˜) + - [visual studio code๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ](#visual-studio-code๋ฅผ-์‚ฌ์šฉํ•˜๊ธฐ) + - [Python ๊ธฐ๋ณธ](#python-๊ธฐ๋ณธ) + - [Python ๊ตฌ๋ฌธ](#python-๊ตฌ๋ฌธ) + - [Python ๋“ค์—ฌ์“ฐ๊ธฐ](#python-๋“ค์—ฌ์“ฐ๊ธฐ) + - [์ฃผ์„](#์ฃผ์„) + - [๋ฐ์ดํ„ฐ ํƒ€์ž…](#๋ฐ์ดํ„ฐ-ํƒ€์ž…) + - [Number](#number) + - [String](#string) + - [Booleans](#booleans) + - [List](#list) + - [Dictionary](#dictionary) + - [Tuple](#tuple) + - [Set](#set) + - [๋ฐ์ดํ„ฐ ํƒ€์ž… ์ฒดํฌ](#๋ฐ์ดํ„ฐ-ํƒ€์ž…-์ฒดํฌ) + - [Python ํŒŒ์ผ](#python-ํŒŒ์ผ) + - [๐Ÿ’ป Exercises - Day 1](#-exercises---day-1) + - [Exercise: Level 1](#exercise-level-1) + - [Exercise: Level 2](#exercise-level-2) + - [Exercise: Level 3](#exercise-level-3) + +# ๐Ÿ“˜ Day 1 + +## ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค + +_30 days of Python_์— ์ฐธ์—ฌํ•˜๊ธฐ๋กœ ๊ฒฐ์ •ํ•˜์‹  ๊ฒƒ์„ **์ถ•ํ•˜๋“œ๋ฆฝ๋‹ˆ๋‹ค**. ์ด ์ฑŒ๋ฆฐ์ง€์—์„œ๋Š” Python ํ”„๋กœ๊ทธ๋ž˜๋จธ๊ฐ€ ๋˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ๋ชจ๋“  ๊ฒƒ๊ณผ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ์ „์ฒด ๊ฐœ๋…์„ ๋ฐฐ์šฐ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ฑŒ๋ฆฐ์ง€๊ฐ€ ๋๋‚˜๋ฉด _30DaysOfPython_ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ฑŒ๋ฆฐ์ง€ ์ธ์ฆ์„œ๋ฅผ ๋ฐ›๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. + +์ฑŒ๋ฆฐ์ง€์— ์ ๊ทน์ ์œผ๋กœ ์ฐธ์—ฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด [30DaysOfPython challenge](https://t.me/ThirtyDaysOfPython) ํ…”๋ ˆ๊ทธ๋žจ ๊ทธ๋ฃน์— ๊ฐ€์ž…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +## ์†Œ๊ฐœ + +Python์€ ๋ฒ”์šฉ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ์œ„ํ•œ ๊ณ ๊ธ‰ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ž…๋‹ˆ๋‹ค. ์˜คํ”ˆ ์†Œ์Šค, ์ธํ„ฐํ”„๋ฆฌํ„ฐ, ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ž…๋‹ˆ๋‹ค. Python์€ ๋„ค๋œ๋ž€๋“œ ํ”„๋กœ๊ทธ๋ž˜๋จธ Guido van Rossum์ด ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. Python ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์˜ ์ด๋ฆ„์€ ์˜๊ตญ ์Šค์ผ€์น˜ ์ฝ”๋ฏธ๋”” ์‹œ๋ฆฌ์ฆˆ *Month Python's Flying Circus* ์—์„œ ํŒŒ์ƒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ฒซ ๋ฒˆ์งธ ๋ฒ„์ „์€ 1991๋…„ 2์›” 20์ผ์— ์ถœ์‹œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด 30์ผ๊ฐ„์˜ Python ์ฑŒ๋ฆฐ์ง€๋Š” ์ตœ์‹  ๋ฒ„์ „์˜ Python์ธ Python 3๋ฅผ ์ฐจ๊ทผ์ฐจ๊ทผ ๋ฐฐ์šธ ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ค„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ฃผ์ œ๋Š” 30์ผ๋กœ ๋‚˜๋‰˜๋ฉฐ, ๋งค์ผ ์ดํ•ดํ•˜๊ธฐ ์‰ฌ์šด ์„ค๋ช…, ์‹ค์ œ ์‚ฌ๋ก€, ๋งŽ์€ ์‹ค์Šต ๋ฐ ํ”„๋กœ์ ํŠธ๊ฐ€ ํฌํ•จ๋œ ์—ฌ๋Ÿฌ ์ฃผ์ œ๊ฐ€ ํฌํ•จ๋ฉ๋‹ˆ๋‹ค. + +์ด ์ฑŒ๋ฆฐ์ง€๋Š” Python ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋ฅผ ๋ฐฐ์šฐ๊ณ ์ž ํ•˜๋Š” ์ดˆ๋ณด์ž์™€ ์ „๋ฌธ๊ฐ€๋ฅผ ์œ„ํ•ด ๊ณ ์•ˆ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ฑŒ๋ฆฐ์ง€๋ฅผ ์™„๋ฃŒํ•˜๋Š” ๋ฐ 30~100์ผ์ด ์†Œ์š”๋  ์ˆ˜ ์žˆ์œผ๋ฉฐ ํ…”๋ ˆ๊ทธ๋žจ ๊ทธ๋ฃน์— ์ ๊ทน์ ์œผ๋กœ ์ฐธ์—ฌํ•˜๋Š” ์‚ฌ๋žŒ๋“ค์ด ์ฑŒ๋ฆฐ์ง€๋ฅผ ์™„๋ฃŒํ•  ํ™•๋ฅ ์ด ๋†’์Šต๋‹ˆ๋‹ค. +์‹œ๊ฐ์  ํ•™์Šต์ž์ด๊ฑฐ๋‚˜ ๋™์˜์ƒ์„ ์„ ํ˜ธํ•˜๋Š” ๊ฒฝ์šฐ ์ด [์™„์ „ ์ดˆ๋ณด๋ฅผ ์œ„ํ•œ Python ๋™์˜์ƒ](https://www.youtube.com/watch?v=11OYpBrhdyM)์œผ๋กœ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +## ์™œ Python์ด๋Š๋ƒ? + +์ธ๊ฐ„์˜ ์–ธ์–ด์— ๋งค์šฐ ๊ฐ€๊น๊ณ  ๋ฐฐ์šฐ๊ธฐ ์‰ฝ๊ณ  ์‚ฌ์šฉํ•˜๊ธฐ ์‰ฌ์šด ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ž…๋‹ˆ๋‹ค. +Python์€ ๋‹ค์–‘ํ•œ ์‚ฐ์—… ๋ฐ ํšŒ์‚ฌ(Google ํฌํ•จ)์—์„œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์›น ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ, ๋ฐ์Šคํฌํ†ฑ ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ, ์‹œ์Šคํ…œ ๊ด€๋ฆฌ ๋ฐ ๊ธฐ๊ณ„ ํ•™์Šต ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๊ฐœ๋ฐœํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. Python์€ ๋ฐ์ดํ„ฐ ๊ณผํ•™ ๋ฐ ๊ธฐ๊ณ„ ํ•™์Šต ์ปค๋ฎค๋‹ˆํ‹ฐ์—์„œ ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๋Š” ์–ธ์–ด์ž…๋‹ˆ๋‹ค. ์ด๊ฒƒ์ด Python ํ•™์Šต์„ ์‹œ์ž‘ํ•˜๋„๋ก ์„ค๋“ํ•˜๊ธฐ์— ์ถฉ๋ถ„ํ•˜๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค. Python์€ ์„ธ์ƒ์„ ์ง€๋ฐฐํ•˜๊ณ  ์žˆ์œผ๋‹ˆ ์ง€๋ฐฐ ๋‹นํ•˜๊ธฐ ์ „์— Python์„ ์ง€๋ฐฐํ•˜์‹ญ์‹œ์˜ค. +## ํ™˜๊ฒฝ ์„ค์ • + +### Python ์„ค์น˜ + +Python ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋ฉด Python์„ ์„ค์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Python์„ [๋‹ค์šด๋กœ๋“œ](https://www.python.org/)ํ•ฉ์‹œ๋‹ค. +Windows ์‚ฌ์šฉ์ž์ธ ๊ฒฝ์šฐ. ๋นจ๊ฐ„์ƒ‰ ๋™๊ทธ๋ผ๋ฏธ ์นœ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. + + + +macOS ์‚ฌ์šฉ์ž์ธ ๊ฒฝ์šฐ. ๋นจ๊ฐ„์ƒ‰ ๋™๊ทธ๋ผ๋ฏธ ์นœ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. + +[![Windows์—์„œ ์„ค์น˜](../images/installing_on_windows.png)](https://www.python.org/) + +Python์ด ์„ค์น˜๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋ ค๋ฉด ์žฅ์น˜ ํ„ฐ๋ฏธ๋„์— ๋‹ค์Œ ๋ช…๋ น์„ ์ž‘์„ฑํ•˜์‹ญ์‹œ์˜ค. + +```shell +python --version +``` + +![Python Version](../images/python_versio.png) + +ํ„ฐ๋ฏธ๋„์—์„œ ๋ณด์‹œ๋‹ค์‹œํ”ผ ์ €๋Š” ํ˜„์žฌ _Python 3.7.5_ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ท€ํ•˜์˜ Python ๋ฒ„์ „์€ ๋‚ด ๋ฒ„์ „๊ณผ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์ง€๋งŒ 3.6 ์ด์ƒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Python ๋ฒ„์ „์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค๋ฉด ์ž˜ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด์ œ ์ปดํ“จํ„ฐ์— Python์ด ์„ค์น˜๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ์„น์…˜์œผ๋กœ ๊ณ„์† ์ง„ํ–‰ํ•˜์‹ญ์‹œ์˜ค. + +### Python ์…ธ + +Python์€ ํ•ด์„๋œ ์Šคํฌ๋ฆฝํŒ… ์–ธ์–ด์ด๋ฏ€๋กœ ์ปดํŒŒ์ผํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ์ฝ”๋“œ๋ฅผ ํ•œ ์ค„์”ฉ ์‹คํ–‰ํ•œ๋‹ค๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค. Python์€ _Python Shell(Python Interactive Shell)_๊ณผ ํ•จ๊ป˜ ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค. ๋‹จ์ผ Python ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ์–ป๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. + +Python Shell์€ ์‚ฌ์šฉ์ž์˜ Python ์ฝ”๋“œ๋ฅผ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค. ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์ฝ”๋“œ๋ฅผ ํ•ด์„ํ•˜์—ฌ ๋‹ค์Œ ์ค„์— ๊ฒฐ๊ณผ๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค. +ํ„ฐ๋ฏธ๋„์ด๋‚˜ ๋ช…๋ น ํ”„๋กฌํ”„ํŠธ(cmd)๋ฅผ ์—ด๊ณ  ์“ฐ๊ธฐ: + +```shell +python +``` + +![Python Scripting Shell](../images/opening_python_shell.png) + +Python ๋Œ€ํ™”ํ˜• ์…ธ์ด ์—ด๋ฆฌ๊ณ  Python ์ฝ”๋“œ(Python ์Šคํฌ๋ฆฝํŠธ)๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ๋ฅผ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค. ๊ธฐํ˜ธ >>> ์˜†์— Python ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  Enter๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค. +Python ์Šคํฌ๋ฆฝํŒ… ์…ธ์—์„œ ์ฒซ ๋ฒˆ์งธ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +![Python script on Python shell](../images/adding_on_python_shell.png) + +ํ›Œ๋ฅญํ•ฉ๋‹ˆ๋‹ค. Python ๋Œ€ํ™”ํ˜• ์…ธ์—์„œ ์ฒซ ๋ฒˆ์งธ Python ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. Python ๋Œ€ํ™”ํ˜• ์…ธ์„ ์–ด๋–ป๊ฒŒ ๋‹ซ์Šต๋‹ˆ๊นŒ? +์…ธ์„ ๋‹ซ์œผ๋ ค๋ฉด ๊ธฐํ˜ธ ์˜†์— >> **exit()** ๋ช…๋ น์„ ์ž‘์„ฑํ•˜๊ณ  Enter ํ‚ค๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค. + +![Exit from python shell](../images/exit_from_shell.png) + +์ด์ œ Python ๋Œ€ํ™”ํ˜• ์…ธ์„ ์—ฌ๋Š” ๋ฐฉ๋ฒ•๊ณผ ์ข…๋ฃŒํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•˜์Šต๋‹ˆ๋‹ค. + +Python์€ Python์ด ์ดํ•ดํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ๊ฒฐ๊ณผ๋ฅผ ์ œ๊ณตํ•˜๊ณ  ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์˜ค๋ฅ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๊ณ ์˜์ ์ธ ์‹ค์ˆ˜๋ฅผ ํ•˜๊ณ  Python์ด ๋ฌด์—‡์„ ๋ฐ˜ํ™˜ํ•˜๋Š”์ง€ ๋ด…์‹œ๋‹ค. + +![Invalid Syntax Error](../images/invalid_syntax_error.png) + +๋ฐ˜ํ™˜๋œ ์˜ค๋ฅ˜์—์„œ ๋ณผ ์ˆ˜ ์žˆ๋“ฏ์ด Python์€ ์šฐ๋ฆฌ๊ฐ€ ์ €์ง€๋ฅธ ์‹ค์ˆ˜์™€ _Syntax Error: invalid syntax_๋ฅผ ์•Œ๊ณ  ์žˆ์„ ์ •๋„๋กœ ์˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค. Python์—์„œ x๋ฅผ ๊ณฑ์…ˆ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ (x)๊ฐ€ Python์—์„œ ์œ ํšจํ•œ ๊ตฌ๋ฌธ์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ตฌ๋ฌธ ์˜ค๋ฅ˜์ž…๋‹ˆ๋‹ค. (**x**) ๋Œ€์‹  ๊ณฑ์…ˆ์— ๋ณ„ํ‘œ(*)๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋ฐ˜ํ™˜๋œ ์˜ค๋ฅ˜๋Š” ์ˆ˜์ •ํ•ด์•ผ ํ•  ์‚ฌํ•ญ์„ ๋ช…ํ™•ํ•˜๊ฒŒ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. + +ํ”„๋กœ๊ทธ๋žจ์—์„œ ์˜ค๋ฅ˜๋ฅผ ์‹๋ณ„ํ•˜๊ณ  ์ œ๊ฑฐํ•˜๋Š” ํ”„๋กœ์„ธ์Šค๋ฅผ *๋””๋ฒ„๊น…*์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. **x** ๋Œ€์‹  *๋ฅผ ๋„ฃ์–ด ๋””๋ฒ„๊น…ํ•ด ๋ด…์‹œ๋‹ค. + +![Fixing Syntax Error](../images/fixing_syntax_error.png) + +๋ฒ„๊ทธ๊ฐ€ ์ˆ˜์ •๋˜์—ˆ๊ณ  ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋˜์—ˆ์œผ๋ฉฐ ์˜ˆ์ƒํ–ˆ๋˜ ๊ฒฐ๊ณผ๋ฅผ ์–ป์—ˆ์Šต๋‹ˆ๋‹ค. ํ”„๋กœ๊ทธ๋ž˜๋จธ๋กœ์„œ ๋งค์ผ ์ด๋Ÿฌํ•œ ์ข…๋ฅ˜์˜ ์˜ค๋ฅ˜๋ฅผ ๋ณด๊ฒŒ ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋””๋ฒ„๊น… ๋ฐฉ๋ฒ•์„ ์•„๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ๋””๋ฒ„๊น…์„ ์ž˜ํ•˜๋ ค๋ฉด ์–ด๋–ค ์ข…๋ฅ˜์˜ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ๋Š”์ง€ ์ดํ•ดํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” Python ์˜ค๋ฅ˜ ์ค‘ ์ผ๋ถ€๋Š” *SyntaxError*, *IndexError*, *NameError*, *ModuleNotFoundError*, *KeyError*, *ImportError*, *AttributeError*, *TypeError*, *ValueError*, *ZeroDivisionError* ๋“ฑ์ž…๋‹ˆ๋‹ค. ์ดํ›„ ์„น์…˜์—์„œ ๋‹ค๋ฅธ Python **_์˜ค๋ฅ˜ ์œ ํ˜•_**์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณผ ๊ฒƒ์ž…๋‹ˆ๋‹ค. + +Python ๋Œ€ํ™”ํ˜• ์…ธ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋” ์—ฐ์Šตํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ํ„ฐ๋ฏธ๋„์ด๋‚˜ ๋ช…๋ น ํ”„๋กฌํ”„ํŠธ๋กœ ์ด๋™ํ•˜์—ฌ **python**์ด๋ผ๋Š” ๋‹จ์–ด๋ฅผ ์”๋‹ˆ๋‹ค. + +![Python Scripting Shell](../images/opening_python_shell.png) + +Python ๋Œ€ํ™”ํ˜• ์…ธ์ด ์—ด๋ฆฝ๋‹ˆ๋‹ค. ๋ช‡ ๊ฐ€์ง€ ๊ธฐ๋ณธ์ ์ธ ์ˆ˜ํ•™ ์—ฐ์‚ฐ(๋”ํ•˜๊ธฐ, ๋นผ๊ธฐ, ๊ณฑํ•˜๊ธฐ, ๋‚˜๋ˆ„๊ธฐ, ๋‚˜๋จธ์ง€, ์ง€์ˆ˜)์„ ์ˆ˜ํ–‰ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +Python ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ ์ „์— ๋จผ์ € ๋ช‡ ๊ฐ€์ง€ ์ˆ˜ํ•™์„ ์ˆ˜ํ–‰ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค: + +- 2 + 3 = 5 +- 3 - 2 = 1 +- 3 \* 2 = 6 +- 3 / 2 = 1.5 +- 3 ^ 2 = 3 x 3 = 9 + +Python์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ถ”๊ฐ€ ์ž‘์—…์ด ์žˆ์Šต๋‹ˆ๋‹ค: + +- 3 % 2 = 1 => ๋‚˜๋จธ์ง€๋ฅผ ๊ตฌํ•จ +- 3 // 2 = 1 => ๋‚˜๋จธ์ง€๋ฅผ ์ œ๊ฑฐ + +์œ„์˜ ์ˆ˜ํ•™์‹์„ Python ์ฝ”๋“œ๋กœ ๋ฐ”๊ฟ”๋ด…์‹œ๋‹ค. Python ์…ธ์ด ์—ด๋ ธ์œผ๋ฉฐ ์…ธ ๋งจ ์ฒ˜์Œ์— ์ฃผ์„์„ ์ž‘์„ฑํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +_comment_๋Š” Python์— ์˜ํ•ด ์‹คํ–‰๋˜์ง€ ์•Š๋Š” ์ฝ”๋“œ์˜ ์ผ๋ถ€์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ฝ”๋“œ๋ฅผ ๋” ์ฝ๊ธฐ ์‰ฝ๊ฒŒ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ์ฝ”๋“œ์— ์ผ๋ถ€ ํ…์ŠคํŠธ๋ฅผ ๋‚จ๊ธธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Python์€ ์ฃผ์„ ๋ถ€๋ถ„์„ ์‹คํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. Python์—์„œ ์ฃผ์„์€ ํ•ด์‹œ(#) ๊ธฐํ˜ธ๋กœ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. +์ด๊ฒƒ์ด Python์—์„œ ์ฃผ์„์„ ์ž‘์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค + +```shell + # ์ฃผ์„์€ ํ•ด์‹œ๋กœ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. + # (#) ์‹ฌ๋ณผ๋กœ ์‹œ์ž‘ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด๊ฒƒ์€ ํŒŒ์ด์ฌ ์ฃผ์„์ž…๋‹ˆ๋‹ค. +``` + +![Maths on python shell](../images/maths_on_python_shell.png) + +๋‹ค์Œ ์„น์…˜์œผ๋กœ ์ด๋™ํ•˜๊ธฐ ์ „์— Python ๋Œ€ํ™”ํ˜• ์…ธ์—์„œ ๋” ๋งŽ์€ ์—ฐ์Šต์„ ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์…ธ์—์„œ _exit()_๋ฅผ ์ž‘์„ฑํ•˜์—ฌ ์—ด๋ฆฐ ์…ธ์„ ๋‹ซ์•˜๋‹ค๊ฐ€ ๋‹ค์‹œ ์—ด์–ด Python ์…ธ์—์„œ ํ…์ŠคํŠธ๋ฅผ ์“ฐ๋Š” ๋ฐฉ๋ฒ•์„ ์—ฐ์Šตํ•ด ๋ด…์‹œ๋‹ค. + +![Writing String on python shell](../images/writing_string_on_shell.png) + +### Visual Studio Code ์„ค์น˜ + +Python ๋Œ€ํ™”ํ˜• ์…ธ์€ ์ž‘์€ ์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋ฅผ ์‹œ๋„ํ•˜๊ณ  ํ…Œ์ŠคํŠธํ•˜๋Š” ๋ฐ ์ ํ•ฉํ•˜์ง€๋งŒ ํฐ ํ”„๋กœ์ ํŠธ์—๋Š” ์ ํ•ฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์‹ค์ œ ์ž‘์—… ํ™˜๊ฒฝ์—์„œ ๊ฐœ๋ฐœ์ž๋Š” ๋‹ค์–‘ํ•œ ์ฝ”๋“œ ํŽธ์ง‘๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ด 30์ผ๊ฐ„์˜ Python ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ฑŒ๋ฆฐ์ง€์—์„œ๋Š” Visual Studio ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Visual Studio Code๋Š” ๋งค์šฐ ์ธ๊ธฐ ์žˆ๋Š” ์˜คํ”ˆ ์†Œ์Šค ํ…์ŠคํŠธ ํŽธ์ง‘๊ธฐ์ž…๋‹ˆ๋‹ค. ๋‚˜๋Š” vscode์˜ ํŒฌ์ด๊ณ  Visual Studio ์ฝ”๋“œ๋ฅผ [๋‹ค์šด๋กœ๋“œ](https://code.visualstudio.com/)ํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•˜๊ณ  ์‹ถ์ง€๋งŒ, ๋‹ค๋ฅธ ํŽธ์ง‘์ž๋ฅผ ์„ ํ˜ธํ•œ๋‹ค๋ฉด ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒƒ์„ ์ž์œ ๋กญ๊ฒŒ ๋”ฐ๋ฅด์‹ญ์‹œ์˜ค. + +[![Visual Studio Code](../images/vscode.png)](https://code.visualstudio.com/) + +Visual Studio Code๋ฅผ ์„ค์น˜ํ•˜์…จ๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. +๋น„๋””์˜ค๋ฅผ ์„ ํ˜ธํ•˜๋Š” ๊ฒฝ์šฐ Python์šฉ Visual Studio Code[๋น„๋””์˜ค ์ž์Šต์„œ](https://www.youtube.com/watch?v=bn7Cx4z-vSo)๋ฅผ ๋”ฐ๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +#### visual studio code๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ + +Visual Studio ์•„์ด์ฝ˜์„ ๋‘ ๋ฒˆ ํด๋ฆญํ•˜์—ฌ Visual Studio ์ฝ”๋“œ๋ฅผ ์—ฝ๋‹ˆ๋‹ค. ์—ด๋ฉด ์ด๋Ÿฐ ์ข…๋ฅ˜์˜ ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค. ๋ ˆ์ด๋ธ”์ด ์ง€์ •๋œ ์•„์ด์ฝ˜์„ ๋”ฐ๋ผํ•ด๋ณด์„ธ์š”. + +![Visual studio Code](../images/vscode_ui.png) + +๋ฐ”ํƒ• ํ™”๋ฉด์— 30DaysOfPython์ด๋ผ๋Š” ํด๋”๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ Visual Studio ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ฝ์‹œ๋‹ค. + +![Opening Project on Visual studio](../images/how_to_open_project_on_vscode.png) + +![Opening a project](../images/opening_project.png) + +ํŒŒ์ผ์„ ์—ด๋ฉด 30DaysOfPython ํ”„๋กœ์ ํŠธ์˜ ๋””๋ ‰ํ† ๋ฆฌ ๋‚ด๋ถ€์— ํŒŒ์ผ๊ณผ ํด๋”๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•œ ๋ฐ”๋กœ ๊ฐ€๊ธฐ๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์—์„œ ๋ณผ ์ˆ˜ ์žˆ๋“ฏ์ด ์ฒซ ๋ฒˆ์งธ ํŒŒ์ผ์ธ helloworld.py๋ฅผ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹น์‹ ๋„ ๋˜‘๊ฐ™์ด ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +![Creating a python file](../images/helloworld.png) + +ํ•˜๋ฃจ๋™์•ˆ ์˜ค๋ž˜ ์ฝ”๋”ฉ์„ ํ•œ ํ›„์— ์ฝ”๋“œ ํŽธ์ง‘๊ธฐ๋ฅผ ๋‹ซ๊ณ  ์‹ถ์Šต๋‹ˆ๊นŒ? ์ด๋ ‡๊ฒŒ ์—ด๋ฆฐ ํ”„๋กœ์ ํŠธ๋ฅผ ๋‹ซ์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. + +![Closing project](../images/closing_opened_project.png) + +์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ์„ค์ •์„ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค. ์ฝ”๋”ฉ์„ ์‹œ์ž‘ํ•ด ๋ด…์‹œ๋‹ค. + +## Python ๊ธฐ๋ณธ + +### Python ๊ตฌ๋ฌธ + +Python ์Šคํฌ๋ฆฝํŠธ๋Š” Python ๋Œ€ํ™”ํ˜• ์…ธ ๋˜๋Š” ์ฝ”๋“œ ํŽธ์ง‘๊ธฐ์—์„œ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Python ํŒŒ์ผ์˜ ํ™•์žฅ์ž๋Š” .py์ž…๋‹ˆ๋‹ค. + +### Python ๋“ค์—ฌ ์“ฐ๊ธฐ + +๋“ค์—ฌ์“ฐ๊ธฐ๋Š” ํ…์ŠคํŠธ์˜ ๊ณต๋ฐฑ์ž…๋‹ˆ๋‹ค. ๋งŽ์€ ์–ธ์–ด์—์„œ ๋“ค์—ฌ์“ฐ๊ธฐ๋Š” ์ฝ”๋“œ ๊ฐ€๋…์„ฑ์„ ๋†’์ด๋Š” ๋ฐ ์‚ฌ์šฉ๋˜์ง€๋งŒ Python์€ ๋“ค์—ฌ์“ฐ๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฝ”๋“œ ๋ธ”๋ก์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์—์„œ๋Š” ์ค‘๊ด„ํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋“ค์—ฌ์“ฐ๊ธฐ ๋Œ€์‹  ์ฝ”๋“œ ๋ธ”๋ก์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. Python ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ ํ”ํžˆ ๋ฐœ์ƒํ•˜๋Š” ๋ฒ„๊ทธ ์ค‘ ํ•˜๋‚˜๋Š” ์ž˜๋ชป๋œ ๋“ค์—ฌ์“ฐ๊ธฐ์ž…๋‹ˆ๋‹ค. + +![Indentation Error](../images/indentation.png) + +### ์ฃผ์„ + +์ฃผ์„์€ ์ฝ”๋“œ๋ฅผ ๋” ์ฝ๊ธฐ ์‰ฝ๊ฒŒ ๋งŒ๋“ค๊ณ  ์ฝ”๋“œ์— ์„ค๋ช…์„ ๋‚จ๊ธฐ๊ธฐ ์œ„ํ•ด ๋งค์šฐ ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. Python์€ ์ฝ”๋“œ์˜ ์ฃผ์„ ๋ถ€๋ถ„์„ ์‹คํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. +Python์—์„œ ํ•ด์‹œ(#)๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ชจ๋“  ํ…์ŠคํŠธ๋Š” ์ฃผ์„์ž…๋‹ˆ๋‹ค. + +**์˜ˆ์‹œ:ํ•œ ๋ฌธ์žฅ ์ฃผ์„** + +```shell + # This is the first comment + # This is the second comment + # Python is eating the world +``` + +**์˜ˆ์‹œ: ์—ฌ๋Ÿฌ ๋ฌธ์žฅ ์ฃผ์„** + +Triple quote can be used for multiline comment if it is not assigned to a variable + +```shell +"""This is multiline comment +multiline comment takes multiple lines. +python is eating the world +""" +``` + +### ๋ฐ์ดํ„ฐ ํƒ€์ž… + +Python์—๋Š” ์—ฌ๋Ÿฌ ์œ ํ˜•์˜ ๋ฐ์ดํ„ฐ ์œ ํ˜•์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์ธ ๊ฒƒ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ ์œ ํ˜•์€ ๋‹ค๋ฅธ ์„น์…˜์—์„œ ์ž์„ธํžˆ ๋‹ค๋ฃฐ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋‹น๋ถ„๊ฐ„ ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ์‚ดํŽด๋ณด๊ณ  ์ต์ˆ™ํ•ด์ง€๋„๋ก ํ•ฉ์‹œ๋‹ค. ์ง€๊ธˆ์€ ๋ช…ํ™•ํ•˜๊ฒŒ ์ดํ•ดํ•˜์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค. + +#### Number + +- Integer: ์ •์ˆ˜(์Œ์ˆ˜, ์˜ ๊ทธ๋ฆฌ๊ณ  ์–‘์ˆ˜) + ์˜ˆ์‹œ: + ... -3, -2, -1, 0, 1, 2, 3 ... +- Float: ์‹ญ์ง„์ˆ˜ + ์˜ˆ์‹œ + ... -3.5, -2.25, -1.0, 0.0, 1.1, 2.2, 3.5 ... +- Complex + ์˜ˆ์‹œ + 1 + j, 2 + 4j + +#### String + +์ž‘์€๋”ฐ์˜ดํ‘œ ๋˜๋Š” ํฐ๋”ฐ์˜ดํ‘œ ์•„๋ž˜์— ์žˆ๋Š” ํ•˜๋‚˜ ์ด์ƒ์˜ ๋ฌธ์ž ๋ชจ์Œ์ž…๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด์ด ๋‘ ๋ฌธ์žฅ ์ด์ƒ์ธ ๊ฒฝ์šฐ ์‚ผ์ค‘ ๋”ฐ์˜ดํ‘œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +**์˜ˆ์‹œ:** + +```py +'Asabeneh' +'Finland' +'Python' +'I love teaching' +'I hope you are enjoying the first day of 30DaysOfPython Challenge' +``` + +#### Boolean + +๋ถ€์šธ ๋ฐ์ดํ„ฐ ์œ ํ˜•์€ True ๋˜๋Š” False ๊ฐ’์ž…๋‹ˆ๋‹ค. T์™€ F๋Š” ํ•ญ์ƒ ๋Œ€๋ฌธ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +**์˜ˆ์‹œ:** + +```python + True # ๋ถˆ์ด ์ผœ์ ธ์žˆ๋‚˜์š”? ๊ทธ๋Ÿฌ๋ฉด ์ฐธ์ž…๋‹ˆ๋‹ค. + False # ๋ถˆ์ด ๊บผ์ ธ์žˆ๋‚˜์š”? ๊ทธ๋Ÿฌ๋ฉด ๊ฑฐ์ง“์ž…๋‹ˆ๋‹ค. +``` + +#### List + +Python ๋ฆฌ์ŠคํŠธ๋Š” ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ ์œ ํ˜• ํ•ญ๋ชฉ์„ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ์ •๋ ฌ๋œ ์ปฌ๋ ‰์…˜์ž…๋‹ˆ๋‹ค. ๋ฆฌ์ŠคํŠธ๋Š” JavaScript์˜ ๋ฐฐ์—ด๊ณผ ๋น„์Šทํ•ฉ๋‹ˆ๋‹ค. + +**Example:** + +```py +[0, 1, 2, 3, 4, 5] # ๋ชจ๋‘ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜• - ์ˆซ์ž ๋ฆฌ์ŠคํŠธ +['Banana', 'Orange', 'Mango', 'Avocado'] # ๋ชจ๋‘ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜• - ๋ฌธ์ž์—ด ๋ฆฌ์ŠคํŠธ(๊ณผ์ผ) +['Finland','Estonia', 'Sweden','Norway'] # ๋ชจ๋‘ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜• - ๋ฌธ์ž์—ด ๋ฆฌ์ŠคํŠธ(๊ตญ๊ฐ€) +['Banana', 10, False, 9.81] # ๋ฆฌ์ŠคํŠธ์˜ ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜• - ๋ฌธ์ž์—ด, ์ •์ˆ˜, ๋ถ€์šธ ๋ฐ ๋ถ€๋™ ์†Œ์ˆ˜์  +``` + +#### Dictionary + +Python ์‚ฌ์ „ ๊ฐœ์ฒด๋Š” ํ‚ค ๊ฐ’ ์Œ ํ˜•์‹์˜ ์ •๋ ฌ๋˜์ง€ ์•Š์€ ๋ฐ์ดํ„ฐ ๋ชจ์Œ์ž…๋‹ˆ๋‹ค. + +**Example:** + +```py +{ +'first_name':'Asabeneh', +'last_name':'Yetayeh', +'country':'Finland', +'age':250, +'is_married':True, +'skills':['JS', 'React', 'Node', 'Python'] +} +``` + +#### Tuple + +ํŠœํ”Œ์€ ๋ชฉ๋ก๊ณผ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜•์˜ ์ •๋ ฌ๋œ ๋ชจ์Œ์ด์ง€๋งŒ ํŠœํ”Œ์ด ์ƒ์„ฑ๋˜๋ฉด ์ˆ˜์ •ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๊ทธ๊ฒƒ๋“ค์€ ๋ณ€ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. + +**Example:** + +```py +('Asabeneh', 'Pawel', 'Brook', 'Abraham', 'Lidiya') # Names +``` + +```py +('Earth', 'Jupiter', 'Neptune', 'Mars', 'Venus', 'Saturn', 'Uranus', 'Mercury') # planets +``` + +#### Set + +์ง‘ํ•ฉ์€ ๋ชฉ๋ก ๋ฐ ํŠœํ”Œ๊ณผ ์œ ์‚ฌํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜•์˜ ๋ชจ์Œ์ž…๋‹ˆ๋‹ค. ๋ชฉ๋ก ๋ฐ ํŠœํ”Œ๊ณผ ๋‹ฌ๋ฆฌ ์ง‘ํ•ฉ์€ ์ˆœ์„œ๊ฐ€ ์ง€์ •๋œ ํ•ญ๋ชฉ ๋ชจ์Œ์ด ์•„๋‹™๋‹ˆ๋‹ค. ์ˆ˜ํ•™์—์„œ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ Python์—์„œ set์€ ๊ณ ์œ ํ•œ ํ•ญ๋ชฉ๋งŒ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. + +์ดํ›„ ์„น์…˜์—์„œ๋Š” ๊ฐ๊ฐ์˜ ๋ชจ๋“  Python ๋ฐ์ดํ„ฐ ์œ ํ˜•์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค. + +**Example:** + +```py +{2, 4, 3, 5} +{3.14, 9.81, 2.7} # order is not important in set +``` + +### ๋ฐ์ดํ„ฐ ํƒ€์ž… ์ฒดํฌ + +ํŠน์ • ๋ฐ์ดํ„ฐ/๋ณ€์ˆ˜์˜ ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด **type** ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ํ„ฐ๋ฏธ๋„์—์„œ ๋‹ค์–‘ํ•œ Python ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค: + +![Checking Data types](../images/checking_data_types.png) + +### Python ํŒŒ์ผ + +๋จผ์ € ํ”„๋กœ์ ํŠธ ํด๋”์ธ 30DaysOfPython์„ ์—ฝ๋‹ˆ๋‹ค. ์ด ํด๋”๊ฐ€ ์—†์œผ๋ฉด 30DaysOfPython์ด๋ผ๋Š” ํด๋” ์ด๋ฆ„์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ์ด ํด๋” ์•ˆ์— helloworld.py๋ผ๋Š” ํŒŒ์ผ์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ์ด์ œ Visual Studio ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Python ๋Œ€ํ™”ํ˜• ์…ธ์—์„œ ์ˆ˜ํ–‰ํ•œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +Python ๋Œ€ํ™”ํ˜• ์…ธ์€ **print**๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์ธ์‡„ํ–ˆ์ง€๋งŒ Visual Studio ์ฝ”๋“œ์—์„œ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ ค๋ฉด ๋‚ด์žฅ ํ•จ์ˆ˜ *print()๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. *print()* ๋‚ด์žฅ ํ•จ์ˆ˜๋Š” *print('arument1', 'argument2', 'argument3')*์™€ ๊ฐ™์ด ํ•˜๋‚˜ ์ด์ƒ์˜ ์ธ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ์˜ˆ๋ฅผ ์ฐธ์กฐํ•˜์‹ญ์‹œ์˜ค. + +**Example:** + +ํŒŒ์ผ ์ด๋ฆ„์€ helloworld.py. + +```py +# Day 1 - 30DaysOfPython Challenge + +print(2 + 3) # addition(+) +print(3 - 1) # subtraction(-) +print(2 * 3) # multiplication(*) +print(3 / 2) # division(/) +print(3 ** 2) # exponential(**) +print(3 % 2) # modulus(%) +print(3 // 2) # Floor division operator(//) + +# Checking data types +print(type(10)) # Int +print(type(3.14)) # Float +print(type(1 + 3j)) # Complex number +print(type('Asabeneh')) # String +print(type([1, 2, 3])) # List +print(type({'name':'Asabeneh'})) # Dictionary +print(type({9.8, 3.14, 2.7})) # Set +print(type((9.8, 3.14, 2.7))) # Tuple +``` + +Python ํŒŒ์ผ์„ ์‹คํ–‰ํ•˜๋ ค๋ฉด ์•„๋ž˜ ์ด๋ฏธ์ง€๋ฅผ ํ™•์ธํ•˜์„ธ์š”. Visual Studio Code์—์„œ ๋…น์ƒ‰ ๋ฒ„ํŠผ์„ ์‹คํ–‰ํ•˜๊ฑฐ๋‚˜ ํ„ฐ๋ฏธ๋„์— *python helloworld.py*๋ฅผ ์ž…๋ ฅํ•˜์—ฌ Python ํŒŒ์ผ์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +![Running python script](../images/running_python_script.png) + +๐ŸŒ• ์ข‹์Šต๋‹ˆ๋‹ค. ๋‹น์‹ ์€ ๋ฐฉ๊ธˆ 1์ผ์ฐจ ๋„์ „์„ ์™„๋ฃŒํ–ˆ๊ณ  ๋‹น์‹ ์€ ์œ„๋Œ€ํ•œ ์—ฌ์ •์— ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ ๋‡Œ์™€ ๊ทผ์œก์„ ์œ„ํ•œ ๋ช‡ ๊ฐ€์ง€ ํ›ˆ๋ จ์„ ํ•ด๋ด…์‹œ๋‹ค. + +## ๐Ÿ’ป Exercises - Day 1 + +### Exercise: Level 1 + +1. ์‚ฌ์šฉ ์ค‘์ธ Python ๋ฒ„์ „ ํ™•์ธ +2. Python ๋Œ€ํ™”ํ˜• ์…ธ์„ ์—ด๊ณ  ๋‹ค์Œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ํ”ผ์—ฐ์‚ฐ์ž๋Š” 3๊ณผ 4์ž…๋‹ˆ๋‹ค. + - ๋”ํ•˜๊ธฐ(+) + - ๋นผ๊ธฐ(-) + - ๊ณฑํ•˜๊ธฐ(\*) + - ๋‚˜๋จธ์ง€(%) + - ๋‚˜๋ˆ„๊ธฐ(/) + - ์ง€์ˆ˜(\*\*) + - ์ •์ˆ˜ ๋‚˜๋ˆ„๊ธฐ(//) +3. Python ๋Œ€ํ™”ํ˜• ์…ธ์— ๋ฌธ์ž์—ด์„ ์”๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค: + - ์ด๋ฆ„ + - ๊ฐ€์กฑ ์ด๋ฆ„ + - ๊ตญ๊ฐ€ ์ด๋ฆ„ + - I am enjoying 30 days of python +4. ๋‹ค์Œ ๋ฐ์ดํ„ฐ์˜ ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ํ™•์ธํ•˜์‹ญ์‹œ์˜ค.: + - 10 + - 9.8 + - 3.14 + - 4 - 4j + - ['Asabeneh', 'Python', 'Finland'] + - ์ด๋ฆ„ + - ๊ฐ€์กฑ ์ด๋ฆ„ + - ๊ตญ๊ฐ€ ์ด๋ฆ„ + +### Exercise: Level 2 + +1. 30DaysOfPython ํด๋” ์•ˆ์— day_1์ด๋ผ๋Š” ํด๋”๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. day_1 ํด๋” ์•ˆ์— python ํŒŒ์ผ helloworld.py๋ฅผ ๋งŒ๋“ค๊ณ  ์งˆ๋ฌธ 1, 2, 3, 4๋ฅผ ๋ฐ˜๋ณตํ•˜์„ธ์š”. Python ํŒŒ์ผ์—์„œ ์ž‘์—…ํ•  ๋•Œ _print()_๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ์žŠ์ง€ ๋งˆ์„ธ์š”. ํŒŒ์ผ์„ ์ €์žฅํ•œ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™ํ•˜์—ฌ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. + +### Exercise: Level 3 + +1. Number(Integer, Float, Complex), String, Boolean, List, Tuple, Set ๋ฐ Dictionary์™€ ๊ฐ™์€ ๋‹ค์–‘ํ•œ Python ๋ฐ์ดํ„ฐ ์œ ํ˜•์— ๋Œ€ํ•œ ์˜ˆ์ œ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. +2. ์ฐธ๊ณ  [Euclidian distance](https://en.wikipedia.org/wiki/Euclidean_distance#:~:text=In%20mathematics%2C%20the%20Euclidean%20distance,being%20called%20the%20Pythagorean%20distance.) (2, 3) ๊ณผ (10, 8) ์‚ฌ์ด + +๐ŸŽ‰ ์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค ! ๐ŸŽ‰ + +[Day 2 >>](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) \ No newline at end of file From 088e613ddeb4ce7e7e32685393a0033f702e4aab Mon Sep 17 00:00:00 2001 From: jshyun1 Date: Fri, 9 Dec 2022 10:34:56 +0900 Subject: [PATCH 15/21] rm lang-ko --- lang-ko/readme_ko.md | 454 ------------------------------------------- 1 file changed, 454 deletions(-) delete mode 100644 lang-ko/readme_ko.md diff --git a/lang-ko/readme_ko.md b/lang-ko/readme_ko.md deleted file mode 100644 index bc628609..00000000 --- a/lang-ko/readme_ko.md +++ /dev/null @@ -1,454 +0,0 @@ -# ๐Ÿ 30 Days Of Python - -|# Day | Topics | -|------|:---------------------------------------------------------:| -| 01 | [Introduction](./readme_ko.md)| -| 02 | [Variables, Built-in Functions](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md)| -| 03 | [Operators](../03_Day_Operators/03_operators.md)| -| 04 | [Strings](../04_Day_Strings/04_strings.md)| -| 05 | [Lists](../05_Day_Lists/05_lists.md)| -| 06 | [Tuples](../06_Day_Tuples/06_tuples.md)| -| 07 | [Sets](../07_Day_Sets/07_sets.md)| -| 08 | [Dictionaries](../08_Day_Dictionaries/08_dictionaries.md)| -| 09 | [Conditionals](../09_Day_Conditionals/09_conditionals.md)| -| 10 | [Loops](../10_Day_Loops/10_loops.md)| -| 11 | [Functions](../11_Day_Functions/11_functions.md)| -| 12 | [Modules](../12_Day_Modules/12_modules.md)| -| 13 | [List Comprehension](../13_Day_List_comprehension/13_list_comprehension.md)| -| 14 | [Higher Order Functions](../14_Day_Higher_order_functions/14_higher_order_functions.md)| -| 15 | [Python Type Errors](../15_Day_Python_type_errors/15_python_type_errors.md)| -| 16 | [Python Date time](../16_Day_Python_date_time/16_python_datetime.md) | -| 17 | [Exception Handling](../17_Day_Exception_handling/17_exception_handling.md)| -| 18 | [Regular Expressions](../18_Day_Regular_expressions/18_regular_expressions.md)| -| 19 | [File Handling](../19_Day_File_handling/19_file_handling.md)| -| 20 | [Python Package Manager](../20_Day_Python_package_manager/20_python_package_manager.md)| -| 21 | [Classes and Objects](../21_Day_Classes_and_objects/21_classes_and_objects.md)| -| 22 | [Web Scraping](../22_Day_Web_scraping/22_web_scraping.md)| -| 23 | [Virtual Environment](../23_Day_Virtual_environment/23_virtual_environment.md)| -| 24 | [Statistics](../24_Day_Statistics/24_statistics.md)| -| 25 | [Pandas](../25_Day_Pandas/25_pandas.md)| -| 26 | [Python web](../26_Day_Python_web/26_python_web.md)| -| 27 | [Python with MongoDB](../27_Day_Python_with_mongodb/27_python_with_mongodb.md)| -| 28 | [API](../28_Day_API/28_API.md)| -| 29 | [Building API](../29_Day_Building_API/29_building_API.md)| -| 30 | [Conclusions](../30_Day_Conclusions/30_conclusions.md)| - -๐Ÿงก๐Ÿงก๐Ÿงก HAPPY CODING ๐Ÿงก๐Ÿงก๐Ÿงก - -
-Support the author to create more educational materials
-Paypal Logo -
- -
-

30 Days Of Python: Day 1 - Introduction

- - - - - Twitter Follow - - - Author: - Asabeneh Yetayeh
- Second Edition: July, 2021 -
-
- - -[Day 2 >>](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) - -![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png) - -- [๐Ÿ 30 Days Of Python](#-30-days-of-python) -- [๐Ÿ“˜ Day 1](#-day-1) - - [ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค](#ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค) - - [์†Œ๊ฐœ](#์†Œ๊ฐœ) - - [์™œ Python์ด๋Š๋ƒ?](#์™œ-python์ด๋Š๋ƒ?) - - [ํ™˜๊ฒฝ ์„ค์ •](#ํ™˜๊ฒฝ-์„ค์ •) - - [Python ์„ค์น˜](#python-์„ค์น˜) - - [Python ์…ธ](#python-์…ธ) - - [Visual Studio Code ์„ค์น˜](#visual-studio-code-์„ค์น˜) - - [visual studio code๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ](#visual-studio-code๋ฅผ-์‚ฌ์šฉํ•˜๊ธฐ) - - [Python ๊ธฐ๋ณธ](#python-๊ธฐ๋ณธ) - - [Python ๊ตฌ๋ฌธ](#python-๊ตฌ๋ฌธ) - - [Python ๋“ค์—ฌ์“ฐ๊ธฐ](#python-๋“ค์—ฌ์“ฐ๊ธฐ) - - [์ฃผ์„](#์ฃผ์„) - - [๋ฐ์ดํ„ฐ ํƒ€์ž…](#๋ฐ์ดํ„ฐ-ํƒ€์ž…) - - [Number](#number) - - [String](#string) - - [Booleans](#booleans) - - [List](#list) - - [Dictionary](#dictionary) - - [Tuple](#tuple) - - [Set](#set) - - [๋ฐ์ดํ„ฐ ํƒ€์ž… ์ฒดํฌ](#๋ฐ์ดํ„ฐ-ํƒ€์ž…-์ฒดํฌ) - - [Python ํŒŒ์ผ](#python-ํŒŒ์ผ) - - [๐Ÿ’ป Exercises - Day 1](#-exercises---day-1) - - [Exercise: Level 1](#exercise-level-1) - - [Exercise: Level 2](#exercise-level-2) - - [Exercise: Level 3](#exercise-level-3) - -# ๐Ÿ“˜ Day 1 - -## ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค - -_30 days of Python_์— ์ฐธ์—ฌํ•˜๊ธฐ๋กœ ๊ฒฐ์ •ํ•˜์‹  ๊ฒƒ์„ **์ถ•ํ•˜๋“œ๋ฆฝ๋‹ˆ๋‹ค**. ์ด ์ฑŒ๋ฆฐ์ง€์—์„œ๋Š” Python ํ”„๋กœ๊ทธ๋ž˜๋จธ๊ฐ€ ๋˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ๋ชจ๋“  ๊ฒƒ๊ณผ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ์ „์ฒด ๊ฐœ๋…์„ ๋ฐฐ์šฐ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ฑŒ๋ฆฐ์ง€๊ฐ€ ๋๋‚˜๋ฉด _30DaysOfPython_ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ฑŒ๋ฆฐ์ง€ ์ธ์ฆ์„œ๋ฅผ ๋ฐ›๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. - -์ฑŒ๋ฆฐ์ง€์— ์ ๊ทน์ ์œผ๋กœ ์ฐธ์—ฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด [30DaysOfPython challenge](https://t.me/ThirtyDaysOfPython) ํ…”๋ ˆ๊ทธ๋žจ ๊ทธ๋ฃน์— ๊ฐ€์ž…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. - -## ์†Œ๊ฐœ - -Python์€ ๋ฒ”์šฉ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ์œ„ํ•œ ๊ณ ๊ธ‰ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ž…๋‹ˆ๋‹ค. ์˜คํ”ˆ ์†Œ์Šค, ์ธํ„ฐํ”„๋ฆฌํ„ฐ, ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ž…๋‹ˆ๋‹ค. Python์€ ๋„ค๋œ๋ž€๋“œ ํ”„๋กœ๊ทธ๋ž˜๋จธ Guido van Rossum์ด ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. Python ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์˜ ์ด๋ฆ„์€ ์˜๊ตญ ์Šค์ผ€์น˜ ์ฝ”๋ฏธ๋”” ์‹œ๋ฆฌ์ฆˆ *Month Python's Flying Circus* ์—์„œ ํŒŒ์ƒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ฒซ ๋ฒˆ์งธ ๋ฒ„์ „์€ 1991๋…„ 2์›” 20์ผ์— ์ถœ์‹œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด 30์ผ๊ฐ„์˜ Python ์ฑŒ๋ฆฐ์ง€๋Š” ์ตœ์‹  ๋ฒ„์ „์˜ Python์ธ Python 3๋ฅผ ์ฐจ๊ทผ์ฐจ๊ทผ ๋ฐฐ์šธ ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ค„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ฃผ์ œ๋Š” 30์ผ๋กœ ๋‚˜๋‰˜๋ฉฐ, ๋งค์ผ ์ดํ•ดํ•˜๊ธฐ ์‰ฌ์šด ์„ค๋ช…, ์‹ค์ œ ์‚ฌ๋ก€, ๋งŽ์€ ์‹ค์Šต ๋ฐ ํ”„๋กœ์ ํŠธ๊ฐ€ ํฌํ•จ๋œ ์—ฌ๋Ÿฌ ์ฃผ์ œ๊ฐ€ ํฌํ•จ๋ฉ๋‹ˆ๋‹ค. - -์ด ์ฑŒ๋ฆฐ์ง€๋Š” Python ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋ฅผ ๋ฐฐ์šฐ๊ณ ์ž ํ•˜๋Š” ์ดˆ๋ณด์ž์™€ ์ „๋ฌธ๊ฐ€๋ฅผ ์œ„ํ•ด ๊ณ ์•ˆ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ฑŒ๋ฆฐ์ง€๋ฅผ ์™„๋ฃŒํ•˜๋Š” ๋ฐ 30~100์ผ์ด ์†Œ์š”๋  ์ˆ˜ ์žˆ์œผ๋ฉฐ ํ…”๋ ˆ๊ทธ๋žจ ๊ทธ๋ฃน์— ์ ๊ทน์ ์œผ๋กœ ์ฐธ์—ฌํ•˜๋Š” ์‚ฌ๋žŒ๋“ค์ด ์ฑŒ๋ฆฐ์ง€๋ฅผ ์™„๋ฃŒํ•  ํ™•๋ฅ ์ด ๋†’์Šต๋‹ˆ๋‹ค. -์‹œ๊ฐ์  ํ•™์Šต์ž์ด๊ฑฐ๋‚˜ ๋™์˜์ƒ์„ ์„ ํ˜ธํ•˜๋Š” ๊ฒฝ์šฐ ์ด [์™„์ „ ์ดˆ๋ณด๋ฅผ ์œ„ํ•œ Python ๋™์˜์ƒ](https://www.youtube.com/watch?v=11OYpBrhdyM)์œผ๋กœ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. - -## ์™œ Python์ด๋Š๋ƒ? - -์ธ๊ฐ„์˜ ์–ธ์–ด์— ๋งค์šฐ ๊ฐ€๊น๊ณ  ๋ฐฐ์šฐ๊ธฐ ์‰ฝ๊ณ  ์‚ฌ์šฉํ•˜๊ธฐ ์‰ฌ์šด ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ž…๋‹ˆ๋‹ค. -Python์€ ๋‹ค์–‘ํ•œ ์‚ฐ์—… ๋ฐ ํšŒ์‚ฌ(Google ํฌํ•จ)์—์„œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์›น ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ, ๋ฐ์Šคํฌํ†ฑ ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ, ์‹œ์Šคํ…œ ๊ด€๋ฆฌ ๋ฐ ๊ธฐ๊ณ„ ํ•™์Šต ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๊ฐœ๋ฐœํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. Python์€ ๋ฐ์ดํ„ฐ ๊ณผํ•™ ๋ฐ ๊ธฐ๊ณ„ ํ•™์Šต ์ปค๋ฎค๋‹ˆํ‹ฐ์—์„œ ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๋Š” ์–ธ์–ด์ž…๋‹ˆ๋‹ค. ์ด๊ฒƒ์ด Python ํ•™์Šต์„ ์‹œ์ž‘ํ•˜๋„๋ก ์„ค๋“ํ•˜๊ธฐ์— ์ถฉ๋ถ„ํ•˜๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค. Python์€ ์„ธ์ƒ์„ ์ง€๋ฐฐํ•˜๊ณ  ์žˆ์œผ๋‹ˆ ์ง€๋ฐฐ ๋‹นํ•˜๊ธฐ ์ „์— Python์„ ์ง€๋ฐฐํ•˜์‹ญ์‹œ์˜ค. -## ํ™˜๊ฒฝ ์„ค์ • - -### Python ์„ค์น˜ - -Python ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋ฉด Python์„ ์„ค์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Python์„ [๋‹ค์šด๋กœ๋“œ](https://www.python.org/)ํ•ฉ์‹œ๋‹ค. -Windows ์‚ฌ์šฉ์ž์ธ ๊ฒฝ์šฐ. ๋นจ๊ฐ„์ƒ‰ ๋™๊ทธ๋ผ๋ฏธ ์นœ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. - - - -macOS ์‚ฌ์šฉ์ž์ธ ๊ฒฝ์šฐ. ๋นจ๊ฐ„์ƒ‰ ๋™๊ทธ๋ผ๋ฏธ ์นœ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. - -[![Windows์—์„œ ์„ค์น˜](../images/installing_on_windows.png)](https://www.python.org/) - -Python์ด ์„ค์น˜๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋ ค๋ฉด ์žฅ์น˜ ํ„ฐ๋ฏธ๋„์— ๋‹ค์Œ ๋ช…๋ น์„ ์ž‘์„ฑํ•˜์‹ญ์‹œ์˜ค. - -```shell -python --version -``` - -![Python Version](../images/python_versio.png) - -ํ„ฐ๋ฏธ๋„์—์„œ ๋ณด์‹œ๋‹ค์‹œํ”ผ ์ €๋Š” ํ˜„์žฌ _Python 3.7.5_ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ท€ํ•˜์˜ Python ๋ฒ„์ „์€ ๋‚ด ๋ฒ„์ „๊ณผ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์ง€๋งŒ 3.6 ์ด์ƒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Python ๋ฒ„์ „์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค๋ฉด ์ž˜ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด์ œ ์ปดํ“จํ„ฐ์— Python์ด ์„ค์น˜๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ์„น์…˜์œผ๋กœ ๊ณ„์† ์ง„ํ–‰ํ•˜์‹ญ์‹œ์˜ค. - -### Python ์…ธ - -Python์€ ํ•ด์„๋œ ์Šคํฌ๋ฆฝํŒ… ์–ธ์–ด์ด๋ฏ€๋กœ ์ปดํŒŒ์ผํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ์ฝ”๋“œ๋ฅผ ํ•œ ์ค„์”ฉ ์‹คํ–‰ํ•œ๋‹ค๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค. Python์€ _Python Shell(Python Interactive Shell)_๊ณผ ํ•จ๊ป˜ ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค. ๋‹จ์ผ Python ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ์–ป๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. - -Python Shell์€ ์‚ฌ์šฉ์ž์˜ Python ์ฝ”๋“œ๋ฅผ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค. ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์ฝ”๋“œ๋ฅผ ํ•ด์„ํ•˜์—ฌ ๋‹ค์Œ ์ค„์— ๊ฒฐ๊ณผ๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค. -ํ„ฐ๋ฏธ๋„์ด๋‚˜ ๋ช…๋ น ํ”„๋กฌํ”„ํŠธ(cmd)๋ฅผ ์—ด๊ณ  ์“ฐ๊ธฐ: - -```shell -python -``` - -![Python Scripting Shell](../images/opening_python_shell.png) - -Python ๋Œ€ํ™”ํ˜• ์…ธ์ด ์—ด๋ฆฌ๊ณ  Python ์ฝ”๋“œ(Python ์Šคํฌ๋ฆฝํŠธ)๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ๋ฅผ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค. ๊ธฐํ˜ธ >>> ์˜†์— Python ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  Enter๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค. -Python ์Šคํฌ๋ฆฝํŒ… ์…ธ์—์„œ ์ฒซ ๋ฒˆ์งธ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. - -![Python script on Python shell](../images/adding_on_python_shell.png) - -ํ›Œ๋ฅญํ•ฉ๋‹ˆ๋‹ค. Python ๋Œ€ํ™”ํ˜• ์…ธ์—์„œ ์ฒซ ๋ฒˆ์งธ Python ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. Python ๋Œ€ํ™”ํ˜• ์…ธ์„ ์–ด๋–ป๊ฒŒ ๋‹ซ์Šต๋‹ˆ๊นŒ? -์…ธ์„ ๋‹ซ์œผ๋ ค๋ฉด ๊ธฐํ˜ธ ์˜†์— >> **exit()** ๋ช…๋ น์„ ์ž‘์„ฑํ•˜๊ณ  Enter ํ‚ค๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค. - -![Exit from python shell](../images/exit_from_shell.png) - -์ด์ œ Python ๋Œ€ํ™”ํ˜• ์…ธ์„ ์—ฌ๋Š” ๋ฐฉ๋ฒ•๊ณผ ์ข…๋ฃŒํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•˜์Šต๋‹ˆ๋‹ค. - -Python์€ Python์ด ์ดํ•ดํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ๊ฒฐ๊ณผ๋ฅผ ์ œ๊ณตํ•˜๊ณ  ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์˜ค๋ฅ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๊ณ ์˜์ ์ธ ์‹ค์ˆ˜๋ฅผ ํ•˜๊ณ  Python์ด ๋ฌด์—‡์„ ๋ฐ˜ํ™˜ํ•˜๋Š”์ง€ ๋ด…์‹œ๋‹ค. - -![Invalid Syntax Error](../images/invalid_syntax_error.png) - -๋ฐ˜ํ™˜๋œ ์˜ค๋ฅ˜์—์„œ ๋ณผ ์ˆ˜ ์žˆ๋“ฏ์ด Python์€ ์šฐ๋ฆฌ๊ฐ€ ์ €์ง€๋ฅธ ์‹ค์ˆ˜์™€ _Syntax Error: invalid syntax_๋ฅผ ์•Œ๊ณ  ์žˆ์„ ์ •๋„๋กœ ์˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค. Python์—์„œ x๋ฅผ ๊ณฑ์…ˆ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ (x)๊ฐ€ Python์—์„œ ์œ ํšจํ•œ ๊ตฌ๋ฌธ์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ตฌ๋ฌธ ์˜ค๋ฅ˜์ž…๋‹ˆ๋‹ค. (**x**) ๋Œ€์‹  ๊ณฑ์…ˆ์— ๋ณ„ํ‘œ(*)๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋ฐ˜ํ™˜๋œ ์˜ค๋ฅ˜๋Š” ์ˆ˜์ •ํ•ด์•ผ ํ•  ์‚ฌํ•ญ์„ ๋ช…ํ™•ํ•˜๊ฒŒ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. - -ํ”„๋กœ๊ทธ๋žจ์—์„œ ์˜ค๋ฅ˜๋ฅผ ์‹๋ณ„ํ•˜๊ณ  ์ œ๊ฑฐํ•˜๋Š” ํ”„๋กœ์„ธ์Šค๋ฅผ *๋””๋ฒ„๊น…*์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. **x** ๋Œ€์‹  *๋ฅผ ๋„ฃ์–ด ๋””๋ฒ„๊น…ํ•ด ๋ด…์‹œ๋‹ค. - -![Fixing Syntax Error](../images/fixing_syntax_error.png) - -๋ฒ„๊ทธ๊ฐ€ ์ˆ˜์ •๋˜์—ˆ๊ณ  ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋˜์—ˆ์œผ๋ฉฐ ์˜ˆ์ƒํ–ˆ๋˜ ๊ฒฐ๊ณผ๋ฅผ ์–ป์—ˆ์Šต๋‹ˆ๋‹ค. ํ”„๋กœ๊ทธ๋ž˜๋จธ๋กœ์„œ ๋งค์ผ ์ด๋Ÿฌํ•œ ์ข…๋ฅ˜์˜ ์˜ค๋ฅ˜๋ฅผ ๋ณด๊ฒŒ ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋””๋ฒ„๊น… ๋ฐฉ๋ฒ•์„ ์•„๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ๋””๋ฒ„๊น…์„ ์ž˜ํ•˜๋ ค๋ฉด ์–ด๋–ค ์ข…๋ฅ˜์˜ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ๋Š”์ง€ ์ดํ•ดํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” Python ์˜ค๋ฅ˜ ์ค‘ ์ผ๋ถ€๋Š” *SyntaxError*, *IndexError*, *NameError*, *ModuleNotFoundError*, *KeyError*, *ImportError*, *AttributeError*, *TypeError*, *ValueError*, *ZeroDivisionError* ๋“ฑ์ž…๋‹ˆ๋‹ค. ์ดํ›„ ์„น์…˜์—์„œ ๋‹ค๋ฅธ Python **_์˜ค๋ฅ˜ ์œ ํ˜•_**์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณผ ๊ฒƒ์ž…๋‹ˆ๋‹ค. - -Python ๋Œ€ํ™”ํ˜• ์…ธ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋” ์—ฐ์Šตํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ํ„ฐ๋ฏธ๋„์ด๋‚˜ ๋ช…๋ น ํ”„๋กฌํ”„ํŠธ๋กœ ์ด๋™ํ•˜์—ฌ **python**์ด๋ผ๋Š” ๋‹จ์–ด๋ฅผ ์”๋‹ˆ๋‹ค. - -![Python Scripting Shell](../images/opening_python_shell.png) - -Python ๋Œ€ํ™”ํ˜• ์…ธ์ด ์—ด๋ฆฝ๋‹ˆ๋‹ค. ๋ช‡ ๊ฐ€์ง€ ๊ธฐ๋ณธ์ ์ธ ์ˆ˜ํ•™ ์—ฐ์‚ฐ(๋”ํ•˜๊ธฐ, ๋นผ๊ธฐ, ๊ณฑํ•˜๊ธฐ, ๋‚˜๋ˆ„๊ธฐ, ๋‚˜๋จธ์ง€, ์ง€์ˆ˜)์„ ์ˆ˜ํ–‰ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. - -Python ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ ์ „์— ๋จผ์ € ๋ช‡ ๊ฐ€์ง€ ์ˆ˜ํ•™์„ ์ˆ˜ํ–‰ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค: - -- 2 + 3 = 5 -- 3 - 2 = 1 -- 3 \* 2 = 6 -- 3 / 2 = 1.5 -- 3 ^ 2 = 3 x 3 = 9 - -Python์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ถ”๊ฐ€ ์ž‘์—…์ด ์žˆ์Šต๋‹ˆ๋‹ค: - -- 3 % 2 = 1 => ๋‚˜๋จธ์ง€๋ฅผ ๊ตฌํ•จ -- 3 // 2 = 1 => ๋‚˜๋จธ์ง€๋ฅผ ์ œ๊ฑฐ - -์œ„์˜ ์ˆ˜ํ•™์‹์„ Python ์ฝ”๋“œ๋กœ ๋ฐ”๊ฟ”๋ด…์‹œ๋‹ค. Python ์…ธ์ด ์—ด๋ ธ์œผ๋ฉฐ ์…ธ ๋งจ ์ฒ˜์Œ์— ์ฃผ์„์„ ์ž‘์„ฑํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. - -_comment_๋Š” Python์— ์˜ํ•ด ์‹คํ–‰๋˜์ง€ ์•Š๋Š” ์ฝ”๋“œ์˜ ์ผ๋ถ€์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ฝ”๋“œ๋ฅผ ๋” ์ฝ๊ธฐ ์‰ฝ๊ฒŒ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ์ฝ”๋“œ์— ์ผ๋ถ€ ํ…์ŠคํŠธ๋ฅผ ๋‚จ๊ธธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Python์€ ์ฃผ์„ ๋ถ€๋ถ„์„ ์‹คํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. Python์—์„œ ์ฃผ์„์€ ํ•ด์‹œ(#) ๊ธฐํ˜ธ๋กœ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. -์ด๊ฒƒ์ด Python์—์„œ ์ฃผ์„์„ ์ž‘์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค - -```shell - # ์ฃผ์„์€ ํ•ด์‹œ๋กœ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. - # (#) ์‹ฌ๋ณผ๋กœ ์‹œ์ž‘ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด๊ฒƒ์€ ํŒŒ์ด์ฌ ์ฃผ์„์ž…๋‹ˆ๋‹ค. -``` - -![Maths on python shell](../images/maths_on_python_shell.png) - -๋‹ค์Œ ์„น์…˜์œผ๋กœ ์ด๋™ํ•˜๊ธฐ ์ „์— Python ๋Œ€ํ™”ํ˜• ์…ธ์—์„œ ๋” ๋งŽ์€ ์—ฐ์Šต์„ ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์…ธ์—์„œ _exit()_๋ฅผ ์ž‘์„ฑํ•˜์—ฌ ์—ด๋ฆฐ ์…ธ์„ ๋‹ซ์•˜๋‹ค๊ฐ€ ๋‹ค์‹œ ์—ด์–ด Python ์…ธ์—์„œ ํ…์ŠคํŠธ๋ฅผ ์“ฐ๋Š” ๋ฐฉ๋ฒ•์„ ์—ฐ์Šตํ•ด ๋ด…์‹œ๋‹ค. - -![Writing String on python shell](../images/writing_string_on_shell.png) - -### Visual Studio Code ์„ค์น˜ - -Python ๋Œ€ํ™”ํ˜• ์…ธ์€ ์ž‘์€ ์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋ฅผ ์‹œ๋„ํ•˜๊ณ  ํ…Œ์ŠคํŠธํ•˜๋Š” ๋ฐ ์ ํ•ฉํ•˜์ง€๋งŒ ํฐ ํ”„๋กœ์ ํŠธ์—๋Š” ์ ํ•ฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์‹ค์ œ ์ž‘์—… ํ™˜๊ฒฝ์—์„œ ๊ฐœ๋ฐœ์ž๋Š” ๋‹ค์–‘ํ•œ ์ฝ”๋“œ ํŽธ์ง‘๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ด 30์ผ๊ฐ„์˜ Python ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ฑŒ๋ฆฐ์ง€์—์„œ๋Š” Visual Studio ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Visual Studio Code๋Š” ๋งค์šฐ ์ธ๊ธฐ ์žˆ๋Š” ์˜คํ”ˆ ์†Œ์Šค ํ…์ŠคํŠธ ํŽธ์ง‘๊ธฐ์ž…๋‹ˆ๋‹ค. ๋‚˜๋Š” vscode์˜ ํŒฌ์ด๊ณ  Visual Studio ์ฝ”๋“œ๋ฅผ [๋‹ค์šด๋กœ๋“œ](https://code.visualstudio.com/)ํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•˜๊ณ  ์‹ถ์ง€๋งŒ, ๋‹ค๋ฅธ ํŽธ์ง‘์ž๋ฅผ ์„ ํ˜ธํ•œ๋‹ค๋ฉด ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒƒ์„ ์ž์œ ๋กญ๊ฒŒ ๋”ฐ๋ฅด์‹ญ์‹œ์˜ค. - -[![Visual Studio Code](../images/vscode.png)](https://code.visualstudio.com/) - -Visual Studio Code๋ฅผ ์„ค์น˜ํ•˜์…จ๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. -๋น„๋””์˜ค๋ฅผ ์„ ํ˜ธํ•˜๋Š” ๊ฒฝ์šฐ Python์šฉ Visual Studio Code[๋น„๋””์˜ค ์ž์Šต์„œ](https://www.youtube.com/watch?v=bn7Cx4z-vSo)๋ฅผ ๋”ฐ๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. - -#### visual studio code๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ - -Visual Studio ์•„์ด์ฝ˜์„ ๋‘ ๋ฒˆ ํด๋ฆญํ•˜์—ฌ Visual Studio ์ฝ”๋“œ๋ฅผ ์—ฝ๋‹ˆ๋‹ค. ์—ด๋ฉด ์ด๋Ÿฐ ์ข…๋ฅ˜์˜ ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค. ๋ ˆ์ด๋ธ”์ด ์ง€์ •๋œ ์•„์ด์ฝ˜์„ ๋”ฐ๋ผํ•ด๋ณด์„ธ์š”. - -![Visual studio Code](../images/vscode_ui.png) - -๋ฐ”ํƒ• ํ™”๋ฉด์— 30DaysOfPython์ด๋ผ๋Š” ํด๋”๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ Visual Studio ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ฝ์‹œ๋‹ค. - -![Opening Project on Visual studio](../images/how_to_open_project_on_vscode.png) - -![Opening a project](../images/opening_project.png) - -ํŒŒ์ผ์„ ์—ด๋ฉด 30DaysOfPython ํ”„๋กœ์ ํŠธ์˜ ๋””๋ ‰ํ† ๋ฆฌ ๋‚ด๋ถ€์— ํŒŒ์ผ๊ณผ ํด๋”๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•œ ๋ฐ”๋กœ ๊ฐ€๊ธฐ๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์—์„œ ๋ณผ ์ˆ˜ ์žˆ๋“ฏ์ด ์ฒซ ๋ฒˆ์งธ ํŒŒ์ผ์ธ helloworld.py๋ฅผ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹น์‹ ๋„ ๋˜‘๊ฐ™์ด ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. - -![Creating a python file](../images/helloworld.png) - -ํ•˜๋ฃจ๋™์•ˆ ์˜ค๋ž˜ ์ฝ”๋”ฉ์„ ํ•œ ํ›„์— ์ฝ”๋“œ ํŽธ์ง‘๊ธฐ๋ฅผ ๋‹ซ๊ณ  ์‹ถ์Šต๋‹ˆ๊นŒ? ์ด๋ ‡๊ฒŒ ์—ด๋ฆฐ ํ”„๋กœ์ ํŠธ๋ฅผ ๋‹ซ์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. - -![Closing project](../images/closing_opened_project.png) - -์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ์„ค์ •์„ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค. ์ฝ”๋”ฉ์„ ์‹œ์ž‘ํ•ด ๋ด…์‹œ๋‹ค. - -## Python ๊ธฐ๋ณธ - -### Python ๊ตฌ๋ฌธ - -Python ์Šคํฌ๋ฆฝํŠธ๋Š” Python ๋Œ€ํ™”ํ˜• ์…ธ ๋˜๋Š” ์ฝ”๋“œ ํŽธ์ง‘๊ธฐ์—์„œ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Python ํŒŒ์ผ์˜ ํ™•์žฅ์ž๋Š” .py์ž…๋‹ˆ๋‹ค. - -### Python ๋“ค์—ฌ ์“ฐ๊ธฐ - -๋“ค์—ฌ์“ฐ๊ธฐ๋Š” ํ…์ŠคํŠธ์˜ ๊ณต๋ฐฑ์ž…๋‹ˆ๋‹ค. ๋งŽ์€ ์–ธ์–ด์—์„œ ๋“ค์—ฌ์“ฐ๊ธฐ๋Š” ์ฝ”๋“œ ๊ฐ€๋…์„ฑ์„ ๋†’์ด๋Š” ๋ฐ ์‚ฌ์šฉ๋˜์ง€๋งŒ Python์€ ๋“ค์—ฌ์“ฐ๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฝ”๋“œ ๋ธ”๋ก์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์—์„œ๋Š” ์ค‘๊ด„ํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋“ค์—ฌ์“ฐ๊ธฐ ๋Œ€์‹  ์ฝ”๋“œ ๋ธ”๋ก์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. Python ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ ํ”ํžˆ ๋ฐœ์ƒํ•˜๋Š” ๋ฒ„๊ทธ ์ค‘ ํ•˜๋‚˜๋Š” ์ž˜๋ชป๋œ ๋“ค์—ฌ์“ฐ๊ธฐ์ž…๋‹ˆ๋‹ค. - -![Indentation Error](../images/indentation.png) - -### ์ฃผ์„ - -์ฃผ์„์€ ์ฝ”๋“œ๋ฅผ ๋” ์ฝ๊ธฐ ์‰ฝ๊ฒŒ ๋งŒ๋“ค๊ณ  ์ฝ”๋“œ์— ์„ค๋ช…์„ ๋‚จ๊ธฐ๊ธฐ ์œ„ํ•ด ๋งค์šฐ ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. Python์€ ์ฝ”๋“œ์˜ ์ฃผ์„ ๋ถ€๋ถ„์„ ์‹คํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. -Python์—์„œ ํ•ด์‹œ(#)๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ชจ๋“  ํ…์ŠคํŠธ๋Š” ์ฃผ์„์ž…๋‹ˆ๋‹ค. - -**์˜ˆ์‹œ:ํ•œ ๋ฌธ์žฅ ์ฃผ์„** - -```shell - # This is the first comment - # This is the second comment - # Python is eating the world -``` - -**์˜ˆ์‹œ: ์—ฌ๋Ÿฌ ๋ฌธ์žฅ ์ฃผ์„** - -Triple quote can be used for multiline comment if it is not assigned to a variable - -```shell -"""This is multiline comment -multiline comment takes multiple lines. -python is eating the world -""" -``` - -### ๋ฐ์ดํ„ฐ ํƒ€์ž… - -Python์—๋Š” ์—ฌ๋Ÿฌ ์œ ํ˜•์˜ ๋ฐ์ดํ„ฐ ์œ ํ˜•์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์ธ ๊ฒƒ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ ์œ ํ˜•์€ ๋‹ค๋ฅธ ์„น์…˜์—์„œ ์ž์„ธํžˆ ๋‹ค๋ฃฐ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋‹น๋ถ„๊ฐ„ ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ์‚ดํŽด๋ณด๊ณ  ์ต์ˆ™ํ•ด์ง€๋„๋ก ํ•ฉ์‹œ๋‹ค. ์ง€๊ธˆ์€ ๋ช…ํ™•ํ•˜๊ฒŒ ์ดํ•ดํ•˜์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค. - -#### Number - -- Integer: ์ •์ˆ˜(์Œ์ˆ˜, ์˜ ๊ทธ๋ฆฌ๊ณ  ์–‘์ˆ˜) - ์˜ˆ์‹œ: - ... -3, -2, -1, 0, 1, 2, 3 ... -- Float: ์‹ญ์ง„์ˆ˜ - ์˜ˆ์‹œ - ... -3.5, -2.25, -1.0, 0.0, 1.1, 2.2, 3.5 ... -- Complex - ์˜ˆ์‹œ - 1 + j, 2 + 4j - -#### String - -์ž‘์€๋”ฐ์˜ดํ‘œ ๋˜๋Š” ํฐ๋”ฐ์˜ดํ‘œ ์•„๋ž˜์— ์žˆ๋Š” ํ•˜๋‚˜ ์ด์ƒ์˜ ๋ฌธ์ž ๋ชจ์Œ์ž…๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด์ด ๋‘ ๋ฌธ์žฅ ์ด์ƒ์ธ ๊ฒฝ์šฐ ์‚ผ์ค‘ ๋”ฐ์˜ดํ‘œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. - -**์˜ˆ์‹œ:** - -```py -'Asabeneh' -'Finland' -'Python' -'I love teaching' -'I hope you are enjoying the first day of 30DaysOfPython Challenge' -``` - -#### Boolean - -๋ถ€์šธ ๋ฐ์ดํ„ฐ ์œ ํ˜•์€ True ๋˜๋Š” False ๊ฐ’์ž…๋‹ˆ๋‹ค. T์™€ F๋Š” ํ•ญ์ƒ ๋Œ€๋ฌธ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. - -**์˜ˆ์‹œ:** - -```python - True # ๋ถˆ์ด ์ผœ์ ธ์žˆ๋‚˜์š”? ๊ทธ๋Ÿฌ๋ฉด ์ฐธ์ž…๋‹ˆ๋‹ค. - False # ๋ถˆ์ด ๊บผ์ ธ์žˆ๋‚˜์š”? ๊ทธ๋Ÿฌ๋ฉด ๊ฑฐ์ง“์ž…๋‹ˆ๋‹ค. -``` - -#### List - -Python ๋ฆฌ์ŠคํŠธ๋Š” ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ ์œ ํ˜• ํ•ญ๋ชฉ์„ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ์ •๋ ฌ๋œ ์ปฌ๋ ‰์…˜์ž…๋‹ˆ๋‹ค. ๋ฆฌ์ŠคํŠธ๋Š” JavaScript์˜ ๋ฐฐ์—ด๊ณผ ๋น„์Šทํ•ฉ๋‹ˆ๋‹ค. - -**Example:** - -```py -[0, 1, 2, 3, 4, 5] # ๋ชจ๋‘ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜• - ์ˆซ์ž ๋ฆฌ์ŠคํŠธ -['Banana', 'Orange', 'Mango', 'Avocado'] # ๋ชจ๋‘ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜• - ๋ฌธ์ž์—ด ๋ฆฌ์ŠคํŠธ(๊ณผ์ผ) -['Finland','Estonia', 'Sweden','Norway'] # ๋ชจ๋‘ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜• - ๋ฌธ์ž์—ด ๋ฆฌ์ŠคํŠธ(๊ตญ๊ฐ€) -['Banana', 10, False, 9.81] # ๋ฆฌ์ŠคํŠธ์˜ ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜• - ๋ฌธ์ž์—ด, ์ •์ˆ˜, ๋ถ€์šธ ๋ฐ ๋ถ€๋™ ์†Œ์ˆ˜์  -``` - -#### Dictionary - -Python ์‚ฌ์ „ ๊ฐœ์ฒด๋Š” ํ‚ค ๊ฐ’ ์Œ ํ˜•์‹์˜ ์ •๋ ฌ๋˜์ง€ ์•Š์€ ๋ฐ์ดํ„ฐ ๋ชจ์Œ์ž…๋‹ˆ๋‹ค. - -**Example:** - -```py -{ -'first_name':'Asabeneh', -'last_name':'Yetayeh', -'country':'Finland', -'age':250, -'is_married':True, -'skills':['JS', 'React', 'Node', 'Python'] -} -``` - -#### Tuple - -ํŠœํ”Œ์€ ๋ชฉ๋ก๊ณผ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜•์˜ ์ •๋ ฌ๋œ ๋ชจ์Œ์ด์ง€๋งŒ ํŠœํ”Œ์ด ์ƒ์„ฑ๋˜๋ฉด ์ˆ˜์ •ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๊ทธ๊ฒƒ๋“ค์€ ๋ณ€ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. - -**Example:** - -```py -('Asabeneh', 'Pawel', 'Brook', 'Abraham', 'Lidiya') # Names -``` - -```py -('Earth', 'Jupiter', 'Neptune', 'Mars', 'Venus', 'Saturn', 'Uranus', 'Mercury') # planets -``` - -#### Set - -์ง‘ํ•ฉ์€ ๋ชฉ๋ก ๋ฐ ํŠœํ”Œ๊ณผ ์œ ์‚ฌํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜•์˜ ๋ชจ์Œ์ž…๋‹ˆ๋‹ค. ๋ชฉ๋ก ๋ฐ ํŠœํ”Œ๊ณผ ๋‹ฌ๋ฆฌ ์ง‘ํ•ฉ์€ ์ˆœ์„œ๊ฐ€ ์ง€์ •๋œ ํ•ญ๋ชฉ ๋ชจ์Œ์ด ์•„๋‹™๋‹ˆ๋‹ค. ์ˆ˜ํ•™์—์„œ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ Python์—์„œ set์€ ๊ณ ์œ ํ•œ ํ•ญ๋ชฉ๋งŒ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. - -์ดํ›„ ์„น์…˜์—์„œ๋Š” ๊ฐ๊ฐ์˜ ๋ชจ๋“  Python ๋ฐ์ดํ„ฐ ์œ ํ˜•์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค. - -**Example:** - -```py -{2, 4, 3, 5} -{3.14, 9.81, 2.7} # order is not important in set -``` - -### ๋ฐ์ดํ„ฐ ํƒ€์ž… ์ฒดํฌ - -ํŠน์ • ๋ฐ์ดํ„ฐ/๋ณ€์ˆ˜์˜ ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด **type** ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ํ„ฐ๋ฏธ๋„์—์„œ ๋‹ค์–‘ํ•œ Python ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค: - -![Checking Data types](../images/checking_data_types.png) - -### Python ํŒŒ์ผ - -๋จผ์ € ํ”„๋กœ์ ํŠธ ํด๋”์ธ 30DaysOfPython์„ ์—ฝ๋‹ˆ๋‹ค. ์ด ํด๋”๊ฐ€ ์—†์œผ๋ฉด 30DaysOfPython์ด๋ผ๋Š” ํด๋” ์ด๋ฆ„์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ์ด ํด๋” ์•ˆ์— helloworld.py๋ผ๋Š” ํŒŒ์ผ์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ์ด์ œ Visual Studio ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Python ๋Œ€ํ™”ํ˜• ์…ธ์—์„œ ์ˆ˜ํ–‰ํ•œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. - -Python ๋Œ€ํ™”ํ˜• ์…ธ์€ **print**๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์ธ์‡„ํ–ˆ์ง€๋งŒ Visual Studio ์ฝ”๋“œ์—์„œ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ ค๋ฉด ๋‚ด์žฅ ํ•จ์ˆ˜ *print()๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. *print()* ๋‚ด์žฅ ํ•จ์ˆ˜๋Š” *print('arument1', 'argument2', 'argument3')*์™€ ๊ฐ™์ด ํ•˜๋‚˜ ์ด์ƒ์˜ ์ธ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ์˜ˆ๋ฅผ ์ฐธ์กฐํ•˜์‹ญ์‹œ์˜ค. - -**Example:** - -ํŒŒ์ผ ์ด๋ฆ„์€ helloworld.py. - -```py -# Day 1 - 30DaysOfPython Challenge - -print(2 + 3) # addition(+) -print(3 - 1) # subtraction(-) -print(2 * 3) # multiplication(*) -print(3 / 2) # division(/) -print(3 ** 2) # exponential(**) -print(3 % 2) # modulus(%) -print(3 // 2) # Floor division operator(//) - -# Checking data types -print(type(10)) # Int -print(type(3.14)) # Float -print(type(1 + 3j)) # Complex number -print(type('Asabeneh')) # String -print(type([1, 2, 3])) # List -print(type({'name':'Asabeneh'})) # Dictionary -print(type({9.8, 3.14, 2.7})) # Set -print(type((9.8, 3.14, 2.7))) # Tuple -``` - -Python ํŒŒ์ผ์„ ์‹คํ–‰ํ•˜๋ ค๋ฉด ์•„๋ž˜ ์ด๋ฏธ์ง€๋ฅผ ํ™•์ธํ•˜์„ธ์š”. Visual Studio Code์—์„œ ๋…น์ƒ‰ ๋ฒ„ํŠผ์„ ์‹คํ–‰ํ•˜๊ฑฐ๋‚˜ ํ„ฐ๋ฏธ๋„์— *python helloworld.py*๋ฅผ ์ž…๋ ฅํ•˜์—ฌ Python ํŒŒ์ผ์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. - -![Running python script](../images/running_python_script.png) - -๐ŸŒ• ์ข‹์Šต๋‹ˆ๋‹ค. ๋‹น์‹ ์€ ๋ฐฉ๊ธˆ 1์ผ์ฐจ ๋„์ „์„ ์™„๋ฃŒํ–ˆ๊ณ  ๋‹น์‹ ์€ ์œ„๋Œ€ํ•œ ์—ฌ์ •์— ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ ๋‡Œ์™€ ๊ทผ์œก์„ ์œ„ํ•œ ๋ช‡ ๊ฐ€์ง€ ํ›ˆ๋ จ์„ ํ•ด๋ด…์‹œ๋‹ค. - -## ๐Ÿ’ป Exercises - Day 1 - -### Exercise: Level 1 - -1. ์‚ฌ์šฉ ์ค‘์ธ Python ๋ฒ„์ „ ํ™•์ธ -2. Python ๋Œ€ํ™”ํ˜• ์…ธ์„ ์—ด๊ณ  ๋‹ค์Œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ํ”ผ์—ฐ์‚ฐ์ž๋Š” 3๊ณผ 4์ž…๋‹ˆ๋‹ค. - - ๋”ํ•˜๊ธฐ(+) - - ๋นผ๊ธฐ(-) - - ๊ณฑํ•˜๊ธฐ(\*) - - ๋‚˜๋จธ์ง€(%) - - ๋‚˜๋ˆ„๊ธฐ(/) - - ์ง€์ˆ˜(\*\*) - - ์ •์ˆ˜ ๋‚˜๋ˆ„๊ธฐ(//) -3. Python ๋Œ€ํ™”ํ˜• ์…ธ์— ๋ฌธ์ž์—ด์„ ์”๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค: - - ์ด๋ฆ„ - - ๊ฐ€์กฑ ์ด๋ฆ„ - - ๊ตญ๊ฐ€ ์ด๋ฆ„ - - I am enjoying 30 days of python -4. ๋‹ค์Œ ๋ฐ์ดํ„ฐ์˜ ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ํ™•์ธํ•˜์‹ญ์‹œ์˜ค.: - - 10 - - 9.8 - - 3.14 - - 4 - 4j - - ['Asabeneh', 'Python', 'Finland'] - - ์ด๋ฆ„ - - ๊ฐ€์กฑ ์ด๋ฆ„ - - ๊ตญ๊ฐ€ ์ด๋ฆ„ - -### Exercise: Level 2 - -1. 30DaysOfPython ํด๋” ์•ˆ์— day_1์ด๋ผ๋Š” ํด๋”๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. day_1 ํด๋” ์•ˆ์— python ํŒŒ์ผ helloworld.py๋ฅผ ๋งŒ๋“ค๊ณ  ์งˆ๋ฌธ 1, 2, 3, 4๋ฅผ ๋ฐ˜๋ณตํ•˜์„ธ์š”. Python ํŒŒ์ผ์—์„œ ์ž‘์—…ํ•  ๋•Œ _print()_๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ์žŠ์ง€ ๋งˆ์„ธ์š”. ํŒŒ์ผ์„ ์ €์žฅํ•œ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™ํ•˜์—ฌ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. - -### Exercise: Level 3 - -1. Number(Integer, Float, Complex), String, Boolean, List, Tuple, Set ๋ฐ Dictionary์™€ ๊ฐ™์€ ๋‹ค์–‘ํ•œ Python ๋ฐ์ดํ„ฐ ์œ ํ˜•์— ๋Œ€ํ•œ ์˜ˆ์ œ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. -2. ์ฐธ๊ณ  [Euclidian distance](https://en.wikipedia.org/wiki/Euclidean_distance#:~:text=In%20mathematics%2C%20the%20Euclidean%20distance,being%20called%20the%20Pythagorean%20distance.) (2, 3) ๊ณผ (10, 8) ์‚ฌ์ด - -๐ŸŽ‰ ์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค ! ๐ŸŽ‰ - -[Day 2 >>](../02_Day_Variables_builtin_functions/02_variables_builtin_functions.md) \ No newline at end of file From f1a3d948b2c264f1bb5bb21e528cea7cf0234d4a Mon Sep 17 00:00:00 2001 From: jshyun1 Date: Fri, 9 Dec 2022 11:25:02 +0900 Subject: [PATCH 16/21] Day 07 10 md --- Korean/07_sets_ko.md | 417 +++++++++++++++++++++++++++++++++++++++ Korean/10_loops_ko.md | 448 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 865 insertions(+) create mode 100644 Korean/07_sets_ko.md create mode 100644 Korean/10_loops_ko.md diff --git a/Korean/07_sets_ko.md b/Korean/07_sets_ko.md new file mode 100644 index 00000000..46092fb7 --- /dev/null +++ b/Korean/07_sets_ko.md @@ -0,0 +1,417 @@ +
30 Days Of Python: Day 7 - Sets Twitter Follow +
+

Author: Asabeneh Yetayeh
Second Edition: July, 2021

+
+ +[<< Day 6](../06_Day_Tuples/06_tuples.md) | [Day 8 >>](../08_Day_Dictionaries/08_dictionaries.md) + +![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png) + +- [๐Ÿ“˜ Day 7](#-day-7) + - [Sets](#sets) + - [์„ธํŠธ ๋งŒ๋“ค๊ธฐ](#์„ธํŠธ-๋งŒ๋“ค๊ธฐ) + - [์„ธํŠธ์˜ ๊ธธ์ด ๊ตฌํ•˜๊ธฐ](#์„ธํŠธ์˜-๊ธธ์ด-๊ตฌํ•˜๊ธฐ) + - [์„ธํŠธ์˜ ํ•ญ๋ชฉ์— ์•ก์„ธ์Šค](#์„ธํŠธ์˜-ํ•ญ๋ชฉ์—-์—‘์„ธ์Šค) + - [ํ•ญ๋ชฉ ํ™•์ธ](#ํ•ญ๋ชฉ-ํ™•์ธ) + - [์„ธํŠธ์— ํ•ญ๋ชฉ ์ถ”๊ฐ€](#์„ธํŠธ์—-ํ•ญ๋ชฉ-์ถ”๊ฐ€) + - [์„ธํŠธ์—์„œ ํ•ญ๋ชฉ ์ œ๊ฑฐ](#์„ธํŠธ์—์„œ-ํ•ญ๋ชฉ-์ œ๊ฑฐ) + - [์„ธํŠธ์˜ ํ•ญ๋ชฉ ์ง€์šฐ๊ธฐ](#์„ธํŠธ์˜-ํ•ญ๋ชฉ-์ง€์šฐ๊ธฐ) + - [์„ธํŠธ ์‚ญ์ œ](#์„ธํŠธ-์‚ญ์ œ) + - [๋ชฉ๋ก์„ ์ง‘ํ•ฉ์œผ๋กœ ๋ณ€ํ™˜](#๋ชฉ๋ก์„-์ง‘ํ•ฉ์œผ๋กœ-๋ณ€ํ™˜) + - [์ง‘ํ•ฉ ๊ฒฐํ•ฉ](#์ง‘ํ•ฉ-๊ฒฐํ•ฉ) + - [๊ต์ฐจ ํ•ญ๋ชฉ ์ฐพ๊ธฐ](#๊ต์ฐจ-ํ•ญ๋ชฉ-์ฐพ๊ธฐ) + - [ํ•˜์œ„ ์ง‘ํ•ฉ ๋ฐ ์ˆ˜ํผ ์ง‘ํ•ฉ ํ™•์ธ](#ํ•˜์œ„-์ง‘ํ•ฉ-๋ฐ-์ˆ˜ํผ-์ง‘ํ•ฉ-ํ™•์ธ) + - [๋‘ ์„ธํŠธ ๊ฐ„์˜ ์ฐจ์ด ํ™•์ธ](#๋‘-์„ธํŠธ-๊ฐ„์˜-์ฐจ์ด-ํ™•์ธ) + - [๋‘ ์ง‘ํ•ฉ ๊ฐ„์˜ ๋Œ€์นญ์  ์ฐจ์ด ์ฐพ๊ธฐ](#๋‘-์ง‘ํ•ฉ-๊ฐ„์˜-๋Œ€์นญ์ -์ฐจ์ด-์ฐพ๊ธฐ) + - [์ง‘ํ•ฉ ๊ฒฐํ•ฉ](#์ง‘ํ•ฉ-๊ฒฐํ•ฉ) + - [๐Ÿ’ป Exercises: Day 7](#-exercises-day-7) + - [Exercises: Level 1](#exercises-level-1) + - [Exercises: Level 2](#exercises-level-2) + - [Exercises: Level 3](#exercises-level-3) + +# ๐Ÿ“˜ Day 7 + +## Sets + +์„ธํŠธ๋Š” ํ•ญ๋ชฉ์˜ ๋ชจ์Œ์ž…๋‹ˆ๋‹ค. ์ดˆ๋“ฑํ•™๊ต ๋˜๋Š” ๊ณ ๋“ฑํ•™๊ต ์ˆ˜ํ•™ ์ˆ˜์—…์œผ๋กœ ๋Œ์•„๊ฐ€๊ฒ ์Šต๋‹ˆ๋‹ค. ์ง‘ํ•ฉ์˜ ์ˆ˜ํ•™ ์ •์˜๋Š” Python์—์„œ๋„ ์ ์šฉ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ง‘ํ•ฉ์€ ์ˆœ์„œ๊ฐ€ ์ง€์ •๋˜์ง€ ์•Š๊ณ  ์ธ๋ฑ์‹ฑ๋˜์ง€ ์•Š์€ ๊ฐœ๋ณ„ ์š”์†Œ์˜ ๋ชจ์Œ์ž…๋‹ˆ๋‹ค. Python์—์„œ ์ง‘ํ•ฉ์€ ๊ณ ์œ ํ•œ ํ•ญ๋ชฉ์„ ์ €์žฅํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋ฉฐ ์ง‘ํ•ฉ ๊ฐ„์— *ํ•ฉ์ง‘ํ•ฉ* , *๊ต์ฐจ* , *์ฐจ์ด* , *๋Œ€์นญ์  ์ฐจ์ด* , *ํ•˜์œ„ ์ง‘ํ•ฉ* , *์ƒ์œ„ ์ง‘ํ•ฉ* ๋ฐ *๋ถ„๋ฆฌ ์ง‘ํ•ฉ* ์„ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +### ์„ธํŠธ ๋งŒ๋“ค๊ธฐ + +์ค‘๊ด„ํ˜ธ {}๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ธํŠธ ๋˜๋Š” *set()* ๋‚ด์žฅ ํ•จ์ˆ˜๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. + +- ๋นˆ ์„ธํŠธ ๋งŒ๋“ค๊ธฐ + +```py +# syntax +st = {} +# or +st = set() +``` + +- ์ดˆ๊ธฐ ํ•ญ๋ชฉ์œผ๋กœ ์„ธํŠธ ๋งŒ๋“ค๊ธฐ + +```py +# syntax +st = {'item1', 'item2', 'item3', 'item4'} +``` + +**์˜ˆ์‹œ:** + +```py +# syntax +fruits = {'banana', 'orange', 'mango', 'lemon'} +``` + +### ์„ธํŠธ์˜ ๊ธธ์ด ๊ตฌํ•˜๊ธฐ + +**len()** ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ง‘ํ•ฉ์˜ ๊ธธ์ด๋ฅผ ์ฐพ์Šต๋‹ˆ๋‹ค. + +```py +# syntax +st = {'item1', 'item2', 'item3', 'item4'} +len(set) +``` + +**์˜ˆ์‹œ:** + +```py +fruits = {'banana', 'orange', 'mango', 'lemon'} +len(fruits) +``` + +### ์„ธํŠธ์˜ ํ•ญ๋ชฉ์— ์•ก์„ธ์Šค + +๋ฃจํ”„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•ญ๋ชฉ์— ์•ก์„ธ์Šคํ•ฉ๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๋Š” ๋ฃจํ”„ ์„น์…˜์—์„œ ์ด๊ฒƒ์„ ๋ณผ ๊ฒƒ์ž…๋‹ˆ๋‹ค + +### ํ•ญ๋ชฉ ํ™•์ธ + +๋ชฉ๋ก์— ํ•ญ๋ชฉ์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ๋ฉค๋ฒ„์‹ญ ์—ฐ์‚ฐ์ž *์—์„œ* ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +```py +# syntax +st = {'item1', 'item2', 'item3', 'item4'} +print("Does set st contain item3? ", 'item3' in st) # Does set st contain item3? True +``` + +**์˜ˆ์‹œ:** + +```py +fruits = {'banana', 'orange', 'mango', 'lemon'} +print('mango' in fruits ) # True +``` + +### ์„ธํŠธ์— ํ•ญ๋ชฉ ์ถ”๊ฐ€ + +์„ธํŠธ๊ฐ€ ์ƒ์„ฑ๋˜๋ฉด ํ•ญ๋ชฉ์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†์œผ๋ฉฐ ํ•ญ๋ชฉ์„ ์ถ”๊ฐ€ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. + +- *add()* ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•˜๋‚˜์˜ ํ•ญ๋ชฉ ์ถ”๊ฐ€ + +```py +# syntax +st = {'item1', 'item2', 'item3', 'item4'} +st.add('item5') +``` + +**์˜ˆ์‹œ:** + +```py +fruits = {'banana', 'orange', 'mango', 'lemon'} +fruits.add('lime') +``` + +- *update()* ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ฌ๋Ÿฌ ํ•ญ๋ชฉ ์ถ”๊ฐ€ *update()* ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์„ธํŠธ์— ์—ฌ๋Ÿฌ ํ•ญ๋ชฉ์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. *update()* ๋Š” ๋ชฉ๋ก ์ธ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +```py +# syntax +st = {'item1', 'item2', 'item3', 'item4'} +st.update(['item5','item6','item7']) +``` + +**์˜ˆ์‹œ:** + +```py +fruits = {'banana', 'orange', 'mango', 'lemon'} +vegetables = ('tomato', 'potato', 'cabbage','onion', 'carrot') +fruits.update(vegetables) +``` + +### ์„ธํŠธ์—์„œ ํ•ญ๋ชฉ ์ œ๊ฑฐ + +*remove()* ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ง‘ํ•ฉ์—์„œ ํ•ญ๋ชฉ์„ ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•ญ๋ชฉ์„ ์ฐพ์„ ์ˆ˜ ์—†์œผ๋ฉด *remove()* ๋ฉ”์„œ๋“œ๋Š” ์˜ค๋ฅ˜๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋ฏ€๋กœ ํ•ด๋‹น ํ•ญ๋ชฉ์ด ์ฃผ์–ด์ง„ ์ง‘ํ•ฉ์— ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜, *discard()* ๋ฉ”์„œ๋“œ๋Š” ์˜ค๋ฅ˜๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +```py +# syntax +st = {'item1', 'item2', 'item3', 'item4'} +st.remove('item2') +``` + +pop() ๋ฉ”์„œ๋“œ๋Š” ๋ชฉ๋ก์—์„œ ์ž„์˜์˜ ํ•ญ๋ชฉ์„ ์ œ๊ฑฐํ•˜๊ณ  ์ œ๊ฑฐ๋œ ํ•ญ๋ชฉ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. + +**์˜ˆ์‹œ:** + +```py +fruits = {'banana', 'orange', 'mango', 'lemon'} +fruits.pop() # removes a random item from the set + +``` + +์ œ๊ฑฐ๋œ ํ•ญ๋ชฉ์— ๊ด€์‹ฌ์ด ์žˆ๋Š” ๊ฒฝ์šฐ. + +```py +fruits = {'banana', 'orange', 'mango', 'lemon'} +removed_item = fruits.pop() +``` + +### ์„ธํŠธ์˜ ํ•ญ๋ชฉ ์ง€์šฐ๊ธฐ + +์„ธํŠธ๋ฅผ ์ง€์šฐ๊ฑฐ๋‚˜ ๋น„์šฐ๋ ค๋ฉด *clear* ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +```py +# syntax +st = {'item1', 'item2', 'item3', 'item4'} +st.clear() +``` + +**์˜ˆ์‹œ:** + +```py +fruits = {'banana', 'orange', 'mango', 'lemon'} +fruits.clear() +print(fruits) # set() +``` + +### ์„ธํŠธ ์‚ญ์ œ + +์„ธํŠธ ์ž์ฒด๋ฅผ ์‚ญ์ œํ•˜๋ ค๋ฉด *del* ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +```py +# syntax +st = {'item1', 'item2', 'item3', 'item4'} +del st +``` + +**์˜ˆ์‹œ:** + +```py +fruits = {'banana', 'orange', 'mango', 'lemon'} +del fruits +``` + +### ๋ชฉ๋ก์„ ์ง‘ํ•ฉ์œผ๋กœ ๋ณ€ํ™˜ + +๋ฆฌ์ŠคํŠธ๋ฅผ ์„ธํŠธ๋กœ, ์„ธํŠธ๋ฅผ ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€ํ™˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ชฉ๋ก์„ ์„ธํŠธ๋กœ ๋ณ€ํ™˜ํ•˜๋ฉด ์ค‘๋ณต ํ•ญ๋ชฉ์ด ์ œ๊ฑฐ๋˜๊ณ  ๊ณ ์œ ํ•œ ํ•ญ๋ชฉ๋งŒ ์˜ˆ์•ฝ๋ฉ๋‹ˆ๋‹ค. + +```py +# syntax +lst = ['item1', 'item2', 'item3', 'item4', 'item1'] +st = set(lst) # {'item2', 'item4', 'item1', 'item3'} - the order is random, because sets in general are unordered +``` + +**์˜ˆ์‹œ:** + +```py +fruits = ['banana', 'orange', 'mango', 'lemon','orange', 'banana'] +fruits = set(fruits) # {'mango', 'lemon', 'banana', 'orange'} +``` + +### ์ง‘ํ•ฉ ๊ฒฐํ•ฉ + +*union()* ๋˜๋Š” *update()* ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‘ ์ง‘ํ•ฉ์„ ๊ฒฐํ•ฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +- Union ์ด ๋ฉ”์„œ๋“œ๋Š” ์ƒˆ ์ง‘ํ•ฉ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. + +```py +# syntax +st1 = {'item1', 'item2', 'item3', 'item4'} +st2 = {'item5', 'item6', 'item7', 'item8'} +st3 = st1.union(st2) +``` + +**์˜ˆ์‹œ:** + +```py +fruits = {'banana', 'orange', 'mango', 'lemon'} +vegetables = {'tomato', 'potato', 'cabbage','onion', 'carrot'} +print(fruits.union(vegetables)) # {'lemon', 'carrot', 'tomato', 'banana', 'mango', 'orange', 'cabbage', 'potato', 'onion'} +``` + +- ์—…๋ฐ์ดํŠธ ์ด ๋ฉ”์„œ๋“œ๋Š” ์ฃผ์–ด์ง„ ์ง‘ํ•ฉ์— ์ง‘ํ•ฉ์„ ์‚ฝ์ž…ํ•ฉ๋‹ˆ๋‹ค. + +```py +# syntax +st1 = {'item1', 'item2', 'item3', 'item4'} +st2 = {'item5', 'item6', 'item7', 'item8'} +st1.update(st2) # st2 contents are added to st1 +``` + +**์˜ˆ์‹œ:** + +```py +fruits = {'banana', 'orange', 'mango', 'lemon'} +vegetables = {'tomato', 'potato', 'cabbage','onion', 'carrot'} +fruits.update(vegetables) +print(fruits) # {'lemon', 'carrot', 'tomato', 'banana', 'mango', 'orange', 'cabbage', 'potato', 'onion'} +``` + +### ๊ต์ฐจ ํ•ญ๋ชฉ ์ฐพ๊ธฐ + +Intersection์€ ๋‘ ์ง‘ํ•ฉ ๋ชจ๋‘์— ์žˆ๋Š” ํ•ญ๋ชฉ ์ง‘ํ•ฉ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ์ฐธ์กฐํ•˜์‹ญ์‹œ์˜ค + +```py +# syntax +st1 = {'item1', 'item2', 'item3', 'item4'} +st2 = {'item3', 'item2'} +st1.intersection(st2) # {'item3', 'item2'} +``` + +**์˜ˆ์‹œ:** + +```py +whole_numbers = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} +even_numbers = {0, 2, 4, 6, 8, 10} +whole_numbers.intersection(even_numbers) # {0, 2, 4, 6, 8, 10} + +python = {'p', 'y', 't', 'h', 'o','n'} +dragon = {'d', 'r', 'a', 'g', 'o','n'} +python.intersection(dragon) # {'o', 'n'} +``` + +### ํ•˜์œ„ ์ง‘ํ•ฉ ๋ฐ ์ˆ˜ํผ ์ง‘ํ•ฉ ํ™•์ธ + +์ง‘ํ•ฉ์€ ๋‹ค๋ฅธ ์ง‘ํ•ฉ์˜ ํ•˜์œ„ ์ง‘ํ•ฉ ๋˜๋Š” ์ƒ์œ„ ์ง‘ํ•ฉ์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +- Subset: *issubset()* +- Super set: *issuperset* + +```py +# syntax +st1 = {'item1', 'item2', 'item3', 'item4'} +st2 = {'item2', 'item3'} +st2.issubset(st1) # True +st1.issuperset(st2) # True +``` + +**์˜ˆ์‹œ:** + +```py +whole_numbers = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} +even_numbers = {0, 2, 4, 6, 8, 10} +whole_numbers.issubset(even_numbers) # False, because it is a super set +whole_numbers.issuperset(even_numbers) # True + +python = {'p', 'y', 't', 'h', 'o','n'} +dragon = {'d', 'r', 'a', 'g', 'o','n'} +python.issubset(dragon) # False +``` + +### ๋‘ ์„ธํŠธ ๊ฐ„์˜ ์ฐจ์ด ํ™•์ธ + +๋‘ ์ง‘ํ•ฉ ๊ฐ„์˜ ์ฐจ์ด๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. + +```py +# syntax +st1 = {'item1', 'item2', 'item3', 'item4'} +st2 = {'item2', 'item3'} +st2.difference(st1) # set() +st1.difference(st2) # {'item1', 'item4'} => st1\st2 +``` + +**์˜ˆ์‹œ:** + +```py +whole_numbers = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} +even_numbers = {0, 2, 4, 6, 8, 10} +whole_numbers.difference(even_numbers) # {1, 3, 5, 7, 9} + +python = {'p', 'y', 't', 'o','n'} +dragon = {'d', 'r', 'a', 'g', 'o','n'} +python.difference(dragon) # {'p', 'y', 't'} - the result is unordered (characteristic of sets) +dragon.difference(python) # {'d', 'r', 'a', 'g'} +``` + +### ๋‘ ์ง‘ํ•ฉ ๊ฐ„์˜ ๋Œ€์นญ์  ์ฐจ์ด ์ฐพ๊ธฐ + +๋‘ ์ง‘ํ•ฉ ๊ฐ„์˜ ๋Œ€์นญ ์ฐจ์ด๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ˆ˜ํ•™์ ์œผ๋กœ ๋‘ ์„ธํŠธ์— ์žˆ๋Š” ํ•ญ๋ชฉ์„ ์ œ์™ธํ•˜๊ณ  ๋‘ ์„ธํŠธ์˜ ๋ชจ๋“  ํ•ญ๋ชฉ์„ ํฌํ•จํ•˜๋Š” ์„ธํŠธ๋ฅผ ๋ฆฌํ„ดํ•œ๋‹ค๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค. (A\B) โˆช (B\A) + +```py +# syntax +st1 = {'item1', 'item2', 'item3', 'item4'} +st2 = {'item2', 'item3'} +# it means (A\B)โˆช(B\A) +st2.symmetric_difference(st1) # {'item1', 'item4'} +``` + +**์˜ˆ์‹œ:** + +```py +whole_numbers = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} +some_numbers = {1, 2, 3, 4, 5} +whole_numbers.symmetric_difference(some_numbers) # {0, 6, 7, 8, 9, 10} + +python = {'p', 'y', 't', 'h', 'o','n'} +dragon = {'d', 'r', 'a', 'g', 'o','n'} +python.symmetric_difference(dragon) # {'r', 't', 'p', 'y', 'g', 'a', 'd', 'h'} +``` + +### ์ง‘ํ•ฉ ๊ฒฐํ•ฉ + +๋‘ ์„ธํŠธ์— ๊ณตํ†ต ํ•ญ๋ชฉ์ด ์—†์œผ๋ฉด ๋ถ„๋ฆฌ ์„ธํŠธ๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. *isdisjoint()* ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‘ ์ง‘ํ•ฉ์ด ๊ฒฐํ•ฉ์ธ์ง€ ๋ถ„๋ฆฌ์ธ์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +```py +# syntax +st1 = {'item1', 'item2', 'item3', 'item4'} +st2 = {'item2', 'item3'} +st2.isdisjoint(st1) # False +``` + +**์˜ˆ์‹œ:** + +```py +even_numbers = {0, 2, 4 ,6, 8} +even_numbers = {1, 3, 5, 7, 9} +even_numbers.isdisjoint(odd_numbers) # True, because no common item + +python = {'p', 'y', 't', 'h', 'o','n'} +dragon = {'d', 'r', 'a', 'g', 'o','n'} +python.isdisjoint(dragon) # False, there are common items {'o', 'n'} +``` + +๐ŸŒ• ๋‹น์‹ ์€ ๋– ์˜ค๋ฅด๋Š” ๋ณ„์ž…๋‹ˆ๋‹ค. ๋‹น์‹ ์€ ๋ฐฉ๊ธˆ 7์ผ์ฐจ ์ฑŒ๋ฆฐ์ง€๋ฅผ ์™„๋ฃŒํ–ˆ์œผ๋ฉฐ ์œ„๋Œ€ํ•จ์„ ํ–ฅํ•œ ๋‹น์‹ ์˜ ๊ธธ์— 7๊ฑธ์Œ ์•ž์„œ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ ๋‡Œ์™€ ๊ทผ์œก์„ ์œ„ํ•œ ๋ช‡ ๊ฐ€์ง€ ํ›ˆ๋ จ์„ ํ•˜์‹ญ์‹œ์˜ค. + +## ๐Ÿ’ป Exercises: Day 7 + +```py +# sets +it_companies = {'Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon'} +A = {19, 22, 24, 20, 25, 26} +B = {19, 22, 20, 25, 26, 24, 28, 27} +age = [22, 19, 24, 25, 26, 24, 25, 24] +``` + +### Exercises: Level 1 + +1. ์ง‘ํ•ฉ it_companies์˜ ๊ธธ์ด ์ฐพ๊ธฐ +2. it_companies์— 'Twitter' ์ถ”๊ฐ€ +3. it_companies ์ง‘ํ•ฉ์— ์—ฌ๋Ÿฌ IT ํšŒ์‚ฌ๋ฅผ ํ•œ ๋ฒˆ์— ์‚ฝ์ž… +4. it_companies ์ง‘ํ•ฉ์—์„œ ํšŒ์‚ฌ ์ค‘ ํ•˜๋‚˜๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค. +5. ์ œ๊ฑฐํ•˜๋‹ค์™€ ๋ฒ„๋ฆฌ๋‹ค์˜ ์ฐจ์ด์ ์€ ๋ฌด์—‡์ธ๊ฐ€์š”? + +### Exercises: Level 2 + +1. A์™€ B๋ฅผ ๊ฒฐํ•ฉ +2. ๊ต์ฐจ ํ•ญ๋ชฉ ์ฐพ๊ธฐ +3. A๋Š” B์˜ ๋ถ€๋ถ„์ง‘ํ•ฉ +4. A์™€ B๋Š” ์„œ๋กœ์†Œ ์ง‘ํ•ฉ์ž…๋‹ˆ๋‹ค. +5. A๋Š” B์™€, B๋Š” A์™€ ์กฐ์ธ +6. A์™€ B์˜ ๋Œ€์นญ ์ฐจ์ด๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ +7. ์„ธํŠธ๋ฅผ ์™„์ „ํžˆ ์‚ญ์ œ + +### Exercises: Level 3 + +1. ์—ฐ๋ น์„ ์„ธํŠธ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ  ๋ชฉ๋ก์˜ ๊ธธ์ด์™€ ์„ธํŠธ์˜ ๊ธธ์ด๋ฅผ ๋น„๊ตํ•ฉ๋‹ˆ๋‹ค. ์–ด๋Š ๊ฒƒ์ด ๋” ํฝ๋‹ˆ๊นŒ? +2. ๋ฌธ์ž์—ด, ๋ชฉ๋ก, ํŠœํ”Œ ๋ฐ ์ง‘ํ•ฉ๊ณผ ๊ฐ™์€ ๋ฐ์ดํ„ฐ ์œ ํ˜•์˜ ์ฐจ์ด์ ์„ ์„ค๋ช…ํ•˜์‹ญ์‹œ์˜ค. +3. *์ €๋Š” ๊ต์‚ฌ์ด๊ณ  ์‚ฌ๋žŒ๋“ค์—๊ฒŒ ์˜๊ฐ์„ ์ฃผ๊ณ  ๊ฐ€๋ฅด์น˜๋Š” ๊ฒƒ์„ ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค.* ๋ฌธ์žฅ์— ์‚ฌ์šฉ๋œ ๋…ํŠนํ•œ ๋‹จ์–ด๋Š” ๋ช‡ ๊ฐœ์ž…๋‹ˆ๊นŒ? ๋ถ„ํ•  ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๊ณ  ๊ณ ์œ ํ•œ ๋‹จ์–ด๋ฅผ ๊ฐ€์ ธ์˜ค๋„๋ก ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. + +๐ŸŽ‰ ์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค! ๐ŸŽ‰ + +[<< 6์ผ์ฐจ](../06_Day_Tuples/06_tuples.md) | [8์ผ์ฐจ >>](../08_Day_Dictionaries/08_dictionaries.md) diff --git a/Korean/10_loops_ko.md b/Korean/10_loops_ko.md new file mode 100644 index 00000000..8b88fd87 --- /dev/null +++ b/Korean/10_loops_ko.md @@ -0,0 +1,448 @@ +
30 Days Of Python: Day 10 - Loops Twitter Follow +
+

Author: Asabeneh Yetayeh
Second Edition: July, 2021

+
+ +[<< Day 9](../09_Day_Conditionals/09_conditionals.md) | [Day 11 >>](../11_Day_Functions/11_functions.md) + +![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png) + +- [๐Ÿ“˜ Day 10](#-day-10) + - [Loops](#loops) + - [While ๋ฃจํ”„](#while-๋ฃจํ”„) + - [Break ๊ณผ Continue - Part 1](#break-and-continue---part-1) + - [For ๋ฃจํ”„](#for-๋ฃจํ”„) + - [Break ๊ณผ Continue - Part 2](#break-and-continue---part-2) + - [๋ฒ”์œ„ ๊ธฐ๋Šฅ](#๋ฒ”์œ„-๊ธฐ๋Šฅ) + - [์ค‘์ฒฉ For ๋ฃจํ”„](#์ค‘์ฒฉ-for-๋ฃจํ”„) + - [For Else](#for-else) + - [Pass](#pass) + - [๐Ÿ’ป Exercises: Day 10](#-exercises-day-10) + - [Exercises: Level 1](#exercises-level-1) + - [Exercises: Level 2](#exercises-level-2) + - [Exercises: Level 3](#exercises-level-3) + +# ๐Ÿ“˜ Day 10 + +## Loops + +์ธ์ƒ์€ ์ผ์ƒ์œผ๋กœ ๊ฐ€๋“ ์ฐจ ์žˆ์Šต๋‹ˆ๋‹ค. ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ์šฐ๋ฆฌ๋Š” ๋˜ํ•œ ๋งŽ์€ ๋ฐ˜๋ณต ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ๋ฐ˜๋ณต ์ž‘์—…์„ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋Š” ๋ฃจํ”„๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Python ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋Š” ๋˜ํ•œ ๋‹ค์Œ ์œ ํ˜•์˜ ๋‘ ๋ฃจํ”„๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. + +1. while loop +2. for loop + +### While ๋ฃจํ”„ + +์šฐ๋ฆฌ๋Š” while ๋ฃจํ”„๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ์˜ˆ์•ฝ์–ด *while* ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ฃผ์–ด์ง„ ์กฐ๊ฑด์ด ๋งŒ์กฑ๋  ๋•Œ๊นŒ์ง€ ๋ฌธ ๋ธ”๋ก์„ ๋ฐ˜๋ณต์ ์œผ๋กœ ์‹คํ–‰ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์กฐ๊ฑด์ด ๊ฑฐ์ง“์ด ๋˜๋ฉด ๋ฃจํ”„ ๋’ค์˜ ์ฝ”๋“œ ํ–‰์ด ๊ณ„์† ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. + +```py + # syntax +while condition: + code goes here +``` + +**์˜ˆ์‹œ:** + +```py +count = 0 +while count < 5: + print(count) + count = count + 1 +#prints from 0 to 4 +``` + +์œ„์˜ while ๋ฃจํ”„์—์„œ count๊ฐ€ 5์ผ ๋•Œ ์กฐ๊ฑด์ด false๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. ์ด๋•Œ ๋ฃจํ”„๊ฐ€ ์ค‘์ง€๋ฉ๋‹ˆ๋‹ค. ์กฐ๊ฑด์ด ๋” ์ด์ƒ ์ฐธ์ด ์•„๋‹ ๋•Œ ์ฝ”๋“œ ๋ธ”๋ก์„ ์‹คํ–‰ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด *else* ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +```py + # syntax +while condition: + code goes here +else: + code goes here +``` + +**์˜ˆ์‹œ:** + +```py +count = 0 +while count < 5: + print(count) + count = count + 1 +#prints from 0 to 4 +``` + +์œ„์˜ ๋ฃจํ”„ ์กฐ๊ฑด์€ count๊ฐ€ 5์ด๊ณ  ๋ฃจํ”„๊ฐ€ ์ค‘์ง€๋˜๊ณ  ์‹คํ–‰์ด else ๋ฌธ์„ ์‹œ์ž‘ํ•˜๋ฉด ๊ฑฐ์ง“์ด ๋ฉ๋‹ˆ๋‹ค. ๊ฒฐ๊ณผ์ ์œผ๋กœ 5๊ฐ€ ์ธ์‡„๋ฉ๋‹ˆ๋‹ค. + +### Break ๊ณผ Continue - Part 1 + +- ์ค‘๋‹จ: ๋ฃจํ”„์—์„œ ๋ฒ—์–ด๋‚˜๊ฑฐ๋‚˜ ์ค‘๋‹จํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์ค‘๋‹จ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +```py +# syntax +while condition: + code goes here + if another_condition: + break +``` + +**์˜ˆ์‹œ:** + +```py +count = 0 +while count < 5: + print(count) + count = count + 1 + if count == 3: + break +``` + +์œ„์˜ while ๋ฃจํ”„๋Š” 0, 1, 2๋งŒ ์ธ์‡„ํ•˜์ง€๋งŒ 3์— ๋„๋‹ฌํ•˜๋ฉด ์ค‘์ง€ํ•ฉ๋‹ˆ๋‹ค. + +- ๊ณ„์†: continue ๋ฌธ์„ ์‚ฌ์šฉํ•˜๋ฉด ํ˜„์žฌ ๋ฐ˜๋ณต์„ ๊ฑด๋„ˆ๋›ฐ๊ณ  ๋‹ค์Œ์„ ๊ณ„์†ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +```py + # syntax +while condition: + code goes here + if another_condition: + continue +``` + +**์˜ˆ์‹œ:** + +```py +count = 0 +while count < 5: + if count == 3: + continue + print(count) + count = count + 1 +``` + +์œ„์˜ while ๋ฃจํ”„๋Š” 0, 1, 2 ๋ฐ 4๋งŒ ์ธ์‡„ํ•ฉ๋‹ˆ๋‹ค(3์„ ๊ฑด๋„ˆ๋œ๋‹ˆ๋‹ค). + +### For ๋ฃจํ”„ + +*for* ํ‚ค์›Œ๋“œ๋Š” ๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์™€ ์œ ์‚ฌํ•˜์ง€๋งŒ ๊ตฌ๋ฌธ์ด ์•ฝ๊ฐ„ ๋‹ค๋ฅธ for ๋ฃจํ”„๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ๋ฃจํ”„๋Š” ์‹œํ€€์Šค(์ฆ‰, ๋ชฉ๋ก, ํŠœํ”Œ, ์‚ฌ์ „, ์ง‘ํ•ฉ ๋˜๋Š” ๋ฌธ์ž์—ด)๋ฅผ ๋ฐ˜๋ณตํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. + +- For loop with list + +```py +# syntax +for iterator in lst: + code goes here +``` + +**์˜ˆ์‹œ:** + +```py +numbers = [0, 1, 2, 3, 4, 5] +for number in numbers: # number is temporary name to refer to the list's items, valid only inside this loop + print(number) # the numbers will be printed line by line, from 0 to 5 +``` + +- For loop with string + +```py +# syntax +for iterator in string: + code goes here +``` + +**์˜ˆ์‹œ:** + +```py +language = 'Python' +for letter in language: + print(letter) + + +for i in range(len(language)): + print(language[i]) +``` + +- For loop with tuple + +```py +# syntax +for iterator in tpl: + code goes here +``` + +**์˜ˆ์‹œ:** + +```py +numbers = (0, 1, 2, 3, 4, 5) +for number in numbers: + print(number) +``` + +- ์‚ฌ์ „์„ ์‚ฌ์šฉํ•œ For ๋ฃจํ”„ ์‚ฌ์ „์„ ํ†ตํ•œ ๋ฃจํ”„๋Š” ์‚ฌ์ „์˜ ํ‚ค๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. + +```py + # syntax +for iterator in dct: + code goes here +``` + +**์˜ˆ์‹œ:** + +```py +person = { + 'first_name':'Asabeneh', + 'last_name':'Yetayeh', + 'age':250, + 'country':'Finland', + 'is_marred':True, + 'skills':['JavaScript', 'React', 'Node', 'MongoDB', 'Python'], + 'address':{ + 'street':'Space street', + 'zipcode':'02210' + } +} +for key in person: + print(key) + +for key, value in person.items(): + print(key, value) # this way we get both keys and values printed out +``` + +- Loops in set + +```py +# syntax +for iterator in st: + code goes here +``` + +**์˜ˆ์‹œ:** + +```py +it_companies = {'Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon'} +for company in it_companies: + print(company) +``` + +### Break ๊ณผ Continue - Part 2 + +์งง์€ ์•Œ๋ฆผ: *์ค‘๋‹จ* : ๋ฃจํ”„๊ฐ€ ์™„๋ฃŒ๋˜๊ธฐ ์ „์— ์ค‘๋‹จํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์ค‘๋‹จ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +```py +# syntax +for iterator in sequence: + code goes here + if condition: + break +``` + +**์˜ˆ์‹œ:** + +```py +numbers = (0,1,2,3,4,5) +for number in numbers: + print(number) + if number == 3: + break +``` + +์œ„์˜ ์˜ˆ์—์„œ ๋ฃจํ”„๋Š” 3์— ๋„๋‹ฌํ•˜๋ฉด ์ค‘์ง€๋ฉ๋‹ˆ๋‹ค. + +๊ณ„์†: ๋ฃจํ”„ ๋ฐ˜๋ณต์—์„œ ์ผ๋ถ€ ๋‹จ๊ณ„๋ฅผ ๊ฑด๋„ˆ๋›ฐ๊ณ  ์‹ถ์„ ๋•Œ ๊ณ„์†์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +```py + # syntax +for iterator in sequence: + code goes here + if condition: + continue +``` + +**์˜ˆ์‹œ:** + +```py +numbers = (0,1,2,3,4,5) +for number in numbers: + print(number) + if number == 3: + continue + print('Next number should be ', number + 1) if number != 5 else print("loop's end") # for short hand conditions need both if and else statements +print('outside the loop') +``` + +์œ„์˜ ์˜ˆ์—์„œ ์ˆซ์ž๊ฐ€ 3์ด๋ฉด ์กฐ๊ฑด *๋‹ค์Œ* ๋‹จ๊ณ„(๋ฃจํ”„ ๋‚ด๋ถ€)๋ฅผ ๊ฑด๋„ˆ๋›ฐ๊ณ  ๋ฐ˜๋ณต์ด ๋‚จ์•„ ์žˆ์œผ๋ฉด ๋ฃจํ”„ ์‹คํ–‰์ด ๊ณ„์†๋ฉ๋‹ˆ๋‹ค. + +### ๋ฒ”์œ„ ๊ธฐ๋Šฅ + +*range()* ํ•จ์ˆ˜๋Š” ์ˆซ์ž ๋ชฉ๋ก์— ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. *๋ฒ”์œ„(์‹œ์ž‘, ๋, ๋‹จ๊ณ„)* ๋Š” ์‹œ์ž‘, ์ข…๋ฃŒ ๋ฐ ์ฆ๋ถ„์˜ ์„ธ ๊ฐ€์ง€ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๊ณ  ์ฆ๋ถ„์€ 1์ž…๋‹ˆ๋‹ค. ๋ฒ”์œ„ ์‹œํ€€์Šค์—๋Š” ์ตœ์†Œ 1๊ฐœ์˜ ์ธ์ˆ˜(์ข…๋ฃŒ)๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๋ฒ”์œ„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‹œํ€€์Šค ๋งŒ๋“ค๊ธฐ + +```py +lst = list(range(11)) +print(lst) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +st = set(range(1, 11)) # 2 arguments indicate start and end of the sequence, step set to default 1 +print(st) # {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + +lst = list(range(0,11,2)) +print(lst) # [0, 2, 4, 6, 8, 10] +st = set(range(0,11,2)) +print(st) # {0, 2, 4, 6, 8, 10} +``` + +```py +# syntax +for iterator in range(start, end, step): +``` + +**์˜ˆ์‹œ:** + +```py +for number in range(11): + print(number) # prints 0 to 10, not including 11 +``` + +### ์ค‘์ฒฉ For ๋ฃจํ”„ + +๋ฃจํ”„ ์•ˆ์— ๋ฃจํ”„๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +```py +# syntax +for x in y: + for t in x: + print(t) +``` + +**์˜ˆ์‹œ:** + +```py +person = { + 'first_name': 'Asabeneh', + 'last_name': 'Yetayeh', + 'age': 250, + 'country': 'Finland', + 'is_marred': True, + 'skills': ['JavaScript', 'React', 'Node', 'MongoDB', 'Python'], + 'address': { + 'street': 'Space street', + 'zipcode': '02210' + } +} +for key in person: + if key == 'skills': + for skill in person['skills']: + print(skill) +``` + +### For Else + +๋ฃจํ”„๊ฐ€ ๋๋‚  ๋•Œ ๋ฉ”์‹œ์ง€๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋ฉด else๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +```py +# syntax +for iterator in range(start, end, step): + do something +else: + print('The loop ended') +``` + +**์˜ˆ์‹œ:** + +```py +for number in range(11): + print(number) # prints 0 to 10, not including 11 +else: + print('The loop stops at', number) +``` + +### Pass + +Python์—์„œ when ๋ฌธ์ด ํ•„์š”ํ•˜์ง€๋งŒ(์„ธ๋ฏธ์ฝœ๋ก  ๋’ค์—) ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์„ ์ข‹์•„ํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ์˜ค๋ฅ˜๋ฅผ ํ”ผํ•˜๊ธฐ ์œ„ํ•ด *pass* ๋ผ๋Š” ๋‹จ์–ด๋ฅผ ์“ธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ ํ–ฅํ›„ ์ง„์ˆ ์„ ์œ„ํ•ด ์ž๋ฆฌ ํ‘œ์‹œ์ž๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +**์˜ˆ์‹œ:** + +```py +for number in range(6): + pass +``` + +๐ŸŒ• ๋‹น์‹ ์€ ํฐ ์ด์ •ํ‘œ๋ฅผ ์„ธ์› ๊ณ , ๋‹น์‹ ์€ ๋ฉˆ์ถœ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๊ณ„์†ํ•˜์„ธ์š”! 10์ผ์ฐจ ์ฑŒ๋ฆฐ์ง€๋ฅผ ๋ฐฉ๊ธˆ ์™„๋ฃŒํ–ˆ์œผ๋ฉฐ ์œ„๋Œ€ํ•จ์„ ํ–ฅํ•œ 10๋‹จ๊ณ„๋ฅผ ์•ž๋‘๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ ๋‡Œ์™€ ๊ทผ์œก์„ ์œ„ํ•œ ๋ช‡ ๊ฐ€์ง€ ์šด๋™์„ ํ•˜์‹ญ์‹œ์˜ค. + +## ๐Ÿ’ป Exercises: Day 10 + +### Exercises: Level 1 + +1. for ๋ฃจํ”„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 0์—์„œ 10๊นŒ์ง€ ๋ฐ˜๋ณตํ•˜๊ณ  while ๋ฃจํ”„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋™์ผํ•œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. + +2. for ๋ฃจํ”„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 10์—์„œ 0๊นŒ์ง€ ๋ฐ˜๋ณตํ•˜๊ณ  while ๋ฃจํ”„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋™์ผํ•œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. + +3. print()๋ฅผ 7๋ฒˆ ํ˜ธ์ถœํ•˜๋Š” ๋ฃจํ”„๋ฅผ ์ž‘์„ฑํ•˜์—ฌ ๋‹ค์Œ ์‚ผ๊ฐํ˜•์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. + + ```py + # + ## + ### + #### + ##### + ###### + ####### + ``` + +4. ์ค‘์ฒฉ ๋ฃจํ”„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์Œ์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. + + ```sh + # # # # # # # # + # # # # # # # # + # # # # # # # # + # # # # # # # # + # # # # # # # # + # # # # # # # # + # # # # # # # # + # # # # # # # # + ``` + +5. ๋‹ค์Œ ํŒจํ„ด์„ ์ธ์‡„ํ•ฉ๋‹ˆ๋‹ค. + + ```sh + 0 x 0 = 0 + 1 x 1 = 1 + 2 x 2 = 4 + 3 x 3 = 9 + 4 x 4 = 16 + 5 x 5 = 25 + 6 x 6 = 36 + 7 x 7 = 49 + 8 x 8 = 64 + 9 x 9 = 81 + 10 x 10 = 100 + ``` + +6. for ๋ฃจํ”„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ['Python', 'Numpy','Pandas','Django', 'Flask'] ๋ชฉ๋ก์„ ๋ฐ˜๋ณตํ•˜๊ณ  ํ•ญ๋ชฉ์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. + +7. for ๋ฃจํ”„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 0์—์„œ 100๊นŒ์ง€ ๋ฐ˜๋ณตํ•˜๊ณ  ์ง์ˆ˜๋งŒ ์ถœ๋ ฅ + +8. for ๋ฃจํ”„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 0์—์„œ 100๊นŒ์ง€ ๋ฐ˜๋ณตํ•˜๊ณ  ํ™€์ˆ˜๋งŒ ์ถœ๋ ฅ + +### Exercises: Level 2 + +1. for ๋ฃจํ”„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 0์—์„œ 100๊นŒ์ง€ ๋ฐ˜๋ณตํ•˜๊ณ  ๋ชจ๋“  ์ˆซ์ž์˜ ํ•ฉ๊ณ„๋ฅผ ์ธ์‡„ํ•ฉ๋‹ˆ๋‹ค. + +```sh +The sum of all numbers is 5050. +``` + +1. for ๋ฃจํ”„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 0์—์„œ 100๊นŒ์ง€ ๋ฐ˜๋ณตํ•˜๊ณ  ๋ชจ๋“  ์ง์ˆ˜์˜ ํ•ฉ๊ณผ ๋ชจ๋“  ์Šน์‚ฐ์˜ ํ•ฉ์„ ์ธ์‡„ํ•ฉ๋‹ˆ๋‹ค. + + ```sh + The sum of all evens is 2550. And the sum of all odds is 2500. + ``` + +### Exercises: Level 3 + +1. ๋ฐ์ดํ„ฐ ํด๋”๋กœ ์ด๋™ํ•˜์—ฌ [countries.py](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/countries.py) ํŒŒ์ผ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๊ตญ๊ฐ€๋ฅผ ์ˆœํ™˜ํ•˜๊ณ  ๋‹จ์–ด *land* ๋ฅผ ํฌํ•จํ•˜๋Š” ๋ชจ๋“  ๊ตญ๊ฐ€๋ฅผ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค. +2. ์ด๊ฒƒ์€ ๊ณผ์ผ ๋ชฉ๋ก์ž…๋‹ˆ๋‹ค. ['banana', 'orange', 'mango', 'lemon'] ๋ฃจํ”„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ˆœ์„œ๋ฅผ ๋’ค์ง‘์Šต๋‹ˆ๋‹ค. +3. ๋ฐ์ดํ„ฐ ํด๋”๋กœ ์ด๋™ํ•˜์—ฌ [countries_data.py](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/countries-data.py) ํŒŒ์ผ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + 1. ๋ฐ์ดํ„ฐ์˜ ์ด ์–ธ์–ด ์ˆ˜๋Š” ์–ผ๋งˆ์ž…๋‹ˆ๊นŒ? + 2. ๋ฐ์ดํ„ฐ์—์„œ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š” 10๊ฐœ ์–ธ์–ด ์ฐพ๊ธฐ + 3. ์„ธ๊ณ„์—์„œ ์ธ๊ตฌ๊ฐ€ ๊ฐ€์žฅ ๋งŽ์€ 10๊ฐœ ๊ตญ๊ฐ€ ์ฐพ๊ธฐ + +๐ŸŽ‰ ์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค! ๐ŸŽ‰ + +[<< Day 9](../09_Day_Conditionals/09_conditionals.md) | [Day 11 >>](../11_Day_Functions/11_functions.md) From 1f2f42bf527f36a4cb6691334ebb0f095e80bc4a Mon Sep 17 00:00:00 2001 From: jshyun1 Date: Fri, 9 Dec 2022 11:27:47 +0900 Subject: [PATCH 17/21] Day 07 10 md --- Korean/04_strings_ko.md | 2 +- Korean/07_sets_ko.md | 2 +- Korean/10_loops_ko.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Korean/04_strings_ko.md b/Korean/04_strings_ko.md index b2d92dee..dc74f7c3 100644 --- a/Korean/04_strings_ko.md +++ b/Korean/04_strings_ko.md @@ -1,5 +1,5 @@
- 30 Days Of Python: Day 4 - Strings Twitter Follow +

30 Days Of Python: Day 4 - Strings

Twitter Follow

Author: Asabeneh Yetayeh
Second Edition: July, 2021

diff --git a/Korean/07_sets_ko.md b/Korean/07_sets_ko.md index 46092fb7..815f51e2 100644 --- a/Korean/07_sets_ko.md +++ b/Korean/07_sets_ko.md @@ -1,4 +1,4 @@ -
30 Days Of Python: Day 7 - Sets Twitter Follow +

30 Days Of Python: Day 7 - Sets

Twitter Follow

Author: Asabeneh Yetayeh
Second Edition: July, 2021

diff --git a/Korean/10_loops_ko.md b/Korean/10_loops_ko.md index 8b88fd87..408d943c 100644 --- a/Korean/10_loops_ko.md +++ b/Korean/10_loops_ko.md @@ -1,4 +1,4 @@ -
30 Days Of Python: Day 10 - Loops Twitter Follow +

30 Days Of Python: Day 10 - Loops

Twitter Follow

Author: Asabeneh Yetayeh
Second Edition: July, 2021

From 3670b7000e417437d909efd8e2882235eb599a30 Mon Sep 17 00:00:00 2001 From: jshyun1 Date: Fri, 9 Dec 2022 11:32:23 +0900 Subject: [PATCH 18/21] kor ver --- Korean/04_strings_ko.md | 26 +++++++++++++------------- Korean/10_loops_ko.md | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Korean/04_strings_ko.md b/Korean/04_strings_ko.md index dc74f7c3..a5e1d774 100644 --- a/Korean/04_strings_ko.md +++ b/Korean/04_strings_ko.md @@ -10,20 +10,20 @@ - [Day 4](#day-4) - [๋ฌธ์ž์—ด](#strings) - - [๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ](#creating-a-string) - - [๋ฌธ์ž์—ด ์—ฐ๊ฒฐ](#string-concatenation) - - [๋ฌธ์ž์—ด์˜ ์ด์Šค์ผ€์ดํ”„ ์‹œํ€€์Šค](#escape-sequences-in-strings) - - [๋ฌธ์ž์—ด ํฌ๋งคํŒ…](#string-formatting) - - [์˜ฌ๋“œ ์Šคํƒ€์ผ ๋ฌธ์ž์—ด ํฌ๋งคํŒ…(% ์—ฐ์‚ฐ์ž)](#old-style-string-formatting--operator) - - [์ƒˆ๋กœ์šด ์Šคํƒ€์ผ ๋ฌธ์ž์—ด ํฌ๋งคํŒ…(str.format)](#new-style-string-formatting-strformat) + - [๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ](#๋ฌธ์ž์—ด-๋งŒ๋“ค๊ธฐ) + - [๋ฌธ์ž์—ด ์—ฐ๊ฒฐ](#๋ฌธ์ž์—ด-์—ฐ๊ฒฐ) + - [๋ฌธ์ž์—ด์˜ ์ด์Šค์ผ€์ดํ”„ ์‹œํ€€์Šค](#๋ฌธ์ž์—ด์˜-์ด์Šค์ผ€์ดํ”„-์‹œํ€€์Šค) + - [๋ฌธ์ž์—ด ํฌ๋งคํŒ…](#๋ฌธ์ž์—ด-ํฌ๋งคํŒ…) + - [์˜ฌ๋“œ ์Šคํƒ€์ผ ๋ฌธ์ž์—ด ํฌ๋งคํŒ…(% ์—ฐ์‚ฐ์ž)](#์˜ฌ๋“œ-์Šคํƒ€์ผ-๋ฌธ์ž์—ด-ํฌ๋งคํŒ…%-์—ฐ์‚ฐ์ž) + - [์ƒˆ๋กœ์šด ์Šคํƒ€์ผ ๋ฌธ์ž์—ด ํฌ๋งคํŒ…(str.format)](#์ƒˆ๋กœ์šด-์Šคํƒ€์ผ-๋ฌธ์ž์—ด-ํฌ๋งคํŒ…str.format) - [๋ฌธ์ž์—ด Interpolation / f-Strings (Python 3.6+)](#string-interpolation--f-strings-python-36) - - [๋ฌธ์ž ์‹œํ€€์Šค๋กœ์„œ์˜ Python ๋ฌธ์ž์—ด](#python-strings-as-sequences-of-characters) - - [์–ธํŒจํ‚น ๋ฌธ์ž](#unpacking-characters) - - [์ธ๋ฑ์Šค๋กœ ๋ฌธ์ž์—ด์˜ ๋ฌธ์ž์— ์•ก์„ธ์Šค](#accessing-characters-in-strings-by-index) - - [ํŒŒ์ด์ฌ ๋ฌธ์ž์—ด ์Šฌ๋ผ์ด์‹ฑ](#slicing-python-strings) - - [๋ฌธ์ž์—ด ๋ฆฌ๋ฒ„์Šค](#reversing-a-string) - - [์Šฌ๋ผ์ด์‹ฑํ•˜๋Š” ๋™์•ˆ ๋ฌธ์ž ๊ฑด๋„ˆ๋›ฐ๊ธฐ](#skipping-characters-while-slicing) - - [๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ](#string-methods) + - [๋ฌธ์ž ์‹œํ€€์Šค๋กœ์„œ์˜ Python ๋ฌธ์ž์—ด](#๋ฌธ์ž-์‹œํ€€์Šค๋กœ์„œ์˜-Python-๋ฌธ์ž์—ด) + - [์–ธํŒจํ‚น ๋ฌธ์ž](#์–ธํŒจํ‚น-๋ฌธ์ž) + - [์ธ๋ฑ์Šค๋กœ ๋ฌธ์ž์—ด์˜ ๋ฌธ์ž์— ์•ก์„ธ์Šค](#์ธ๋ฑ์Šค๋กœ-๋ฌธ์ž์—ด์˜-๋ฌธ์ž์—-์•ก์„ธ์Šค) + - [ํŒŒ์ด์ฌ ๋ฌธ์ž์—ด ์Šฌ๋ผ์ด์‹ฑ](#ํŒŒ์ด์ฌ-๋ฌธ์ž์—ด-์Šฌ๋ผ์ด์‹ฑ) + - [๋ฌธ์ž์—ด ๋ฆฌ๋ฒ„์Šค](#๋ฌธ์ž์—ด-๋ฆฌ๋ฒ„์Šค) + - [์Šฌ๋ผ์ด์‹ฑํ•˜๋Š” ๋™์•ˆ ๋ฌธ์ž ๊ฑด๋„ˆ๋›ฐ๊ธฐ](#์Šฌ๋ผ์ด์‹ฑํ•˜๋Š”-๋™์•ˆ-๋ฌธ์ž-๊ฑด๋„ˆ๋›ฐ๊ธฐ) + - [๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ](#๋ฌธ์ž์—ด-๋ฉ”์„œ๋“œ) - [๐Ÿ’ป Exercises - Day 4](#-exercises---day-4) # Day 4 diff --git a/Korean/10_loops_ko.md b/Korean/10_loops_ko.md index 408d943c..0b6f58d9 100644 --- a/Korean/10_loops_ko.md +++ b/Korean/10_loops_ko.md @@ -10,9 +10,9 @@ - [๐Ÿ“˜ Day 10](#-day-10) - [Loops](#loops) - [While ๋ฃจํ”„](#while-๋ฃจํ”„) - - [Break ๊ณผ Continue - Part 1](#break-and-continue---part-1) + - [Break ๊ณผ Continue - Part 1](#break-๊ณผ-continue---part-1) - [For ๋ฃจํ”„](#for-๋ฃจํ”„) - - [Break ๊ณผ Continue - Part 2](#break-and-continue---part-2) + - [Break ๊ณผ Continue - Part 2](#break-๊ณผ-continue---part-2) - [๋ฒ”์œ„ ๊ธฐ๋Šฅ](#๋ฒ”์œ„-๊ธฐ๋Šฅ) - [์ค‘์ฒฉ For ๋ฃจํ”„](#์ค‘์ฒฉ-for-๋ฃจํ”„) - [For Else](#for-else) From 0b19ebad50136280bab91d261a062bdeac926a4c Mon Sep 17 00:00:00 2001 From: ShinYooJung Date: Fri, 9 Dec 2022 14:39:31 +0900 Subject: [PATCH 19/21] Add Day 5 Korean Translation --- Korean/05_Day_Lists/05_lists.md | 588 ++++++++++++++++++++++++++++++++ 1 file changed, 588 insertions(+) create mode 100644 Korean/05_Day_Lists/05_lists.md diff --git a/Korean/05_Day_Lists/05_lists.md b/Korean/05_Day_Lists/05_lists.md new file mode 100644 index 00000000..4b4e89a1 --- /dev/null +++ b/Korean/05_Day_Lists/05_lists.md @@ -0,0 +1,588 @@ +
+

30 Days Of Python: Day 5 - Lists

+ + + + + Twitter Follow + + +Author: +Asabeneh Yetayeh
+ Second Edition: July - 2021 +
+ +
+ +[<< Day 4](../04_Day_Strings/04_strings.md) | [Day 6 >>](../06_Day_Tuples/06_tuples.md) + +![30DaysOfPython](../../images/30DaysOfPython_banner3@2x.png) + +- [Day 5](#day-5) + - [Lists](#lists) + - [How to Create a List](#how-to-create-a-list) + - [Accessing List Items Using Positive Indexing](#accessing-list-items-using-positive-indexing) + - [Accessing List Items Using Negative Indexing](#accessing-list-items-using-negative-indexing) + - [Unpacking List Items](#unpacking-list-items) + - [Slicing Items from a List](#slicing-items-from-a-list) + - [Modifying Lists](#modifying-lists) + - [Checking Items in a List](#checking-items-in-a-list) + - [Adding Items to a List](#adding-items-to-a-list) + - [Inserting Items into a List](#inserting-items-into-a-list) + - [Removing Items from a List](#removing-items-from-a-list) + - [Removing Items Using Pop](#removing-items-using-pop) + - [Removing Items Using Del](#removing-items-using-del) + - [Clearing List Items](#clearing-list-items) + - [Copying a List](#copying-a-list) + - [Joining Lists](#joining-lists) + - [Counting Items in a List](#counting-items-in-a-list) + - [Finding Index of an Item](#finding-index-of-an-item) + - [Reversing a List](#reversing-a-list) + - [Sorting List Items](#sorting-list-items) + - [๐Ÿ’ป Exercises: Day 5](#-exercises-day-5) + - [Exercises: Level 1](#exercises-level-1) + - [Exercises: Level 2](#exercises-level-2) + +# Day 5 + +## Lists + +ํŒŒ์ด์ฌ์—๋Š” ๋„ค ๊ฐ€์ง€ ์ปฌ๋ ‰์…˜ ์ž๋ฃŒํ˜•์ด ์žˆ์Šต๋‹ˆ๋‹ค. + +- List: ์ •๋ ฌ๋˜๊ณ  ๋ณ€๊ฒฝ ๊ฐ€๋Šฅ(์ˆ˜์ • ๊ฐ€๋Šฅ)ํ•œ ์ปฌ๋ ‰์…˜์ž…๋‹ˆ๋‹ค. ์ค‘๋ณต ๊ฐ’์„ ํ—ˆ์šฉํ•ฉ๋‹ˆ๋‹ค. +- Tuple: ์ •๋ ฌ๋˜๊ณ  ๋ณ€๊ฒฝ ๋ถˆ๊ฐ€๋Šฅํ•˜๊ฑฐ๋‚˜ ์ˆ˜์ • ๋ถˆ๊ฐ€๋Šฅํ•œ(๋ถˆ๋ณ€) ์ปฌ๋ ‰์…˜์ž…๋‹ˆ๋‹ค. ์ค‘๋ณต ๊ฐ’์„ ํ—ˆ์šฉํ•ฉ๋‹ˆ๋‹ค. +- Set: ์ˆœ์„œ๊ฐ€ ์ง€์ •๋˜์ง€ ์•Š๊ณ  ์ธ๋ฑ์Šค๊ฐ€ ์—†๊ณ  ์ˆ˜์ •ํ•  ์ˆ˜ ์—†๋Š” ์ปฌ๋ ‰์…˜์ด์ง€๋งŒ ์ƒˆ ์•„์ดํ…œ์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ค‘๋ณต ๊ฐ’์€ ํ—ˆ์šฉ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. +- Dictionary: ์ •๋ ฌ๋˜์ง€ ์•Š๊ณ  ๋ณ€๊ฒฝ ๊ฐ€๋Šฅ(์ˆ˜์ • ๊ฐ€๋Šฅ)ํ•˜๋ฉฐ ์ธ๋ฑ์Šค๊ฐ€ ์žˆ๋Š” ์ปฌ๋ ‰์…˜์ž…๋‹ˆ๋‹ค. ์ค‘๋ณต ๊ฐ’์ด ์—†์Šต๋‹ˆ๋‹ค. + +๋ฆฌ์ŠคํŠธ๋Š” ์ •๋ ฌ๋˜๊ณ  ์ˆ˜์ •(๋ณ€๊ฒฝ) ๊ฐ€๋Šฅํ•œ ๋‹ค์–‘ํ•œ ์ž๋ฃŒํ˜•์˜ ์ปฌ๋ ‰์…˜์ž…๋‹ˆ๋‹ค. ๋ชฉ๋ก์€ ๋น„์–ด ์žˆ๊ฑฐ๋‚˜ ๋‹ค๋ฅธ ์ž๋ฃŒํ˜• ์•„์ดํ…œ์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +### How to Create a List + +ํŒŒ์ด์ฌ์—์„œ ๋ฆฌ์ŠคํŠธ๋Š” ๋‘๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค: + +- list ๋‚ด์žฅ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉ + +```py +# syntax +lst = list() +``` + +```py +empty_list = list() # ์ด๊ฑด ๋นˆ ๋ฆฌ์ŠคํŠธ ์ž…๋‹ˆ๋‹ค, ๋ฆฌ์ŠคํŠธ ์•ˆ์— ์•„๋ฌด ๊ฐ’๋„ ์—†์Šต๋‹ˆ๋‹ค +print(len(empty_list)) # 0 +``` + +- ๋Œ€๊ด„ํ˜ธ ์‚ฌ์šฉ, [] + +```py +# syntax +lst = [] +``` + +```py +empty_list = [] # ์ด๊ฑด ๋นˆ ๋ฆฌ์ŠคํŠธ ์ž…๋‹ˆ๋‹ค, ๋ฆฌ์ŠคํŠธ ์•ˆ์— ์•„๋ฌด ๊ฐ’๋„ ์—†์Šต๋‹ˆ๋‹ค +print(len(empty_list)) # 0 +``` + +์ดˆ๊ธฐ ๊ฐ’์ด ์žˆ๋Š” ๋ฆฌ์ŠคํŠธ์ž…๋‹ˆ๋‹ค. _len()_ ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ์˜ ๊ธธ์ด๋ฅผ ์ฐพ์Šต๋‹ˆ๋‹ค. + +```py +fruits = ['banana', 'orange', 'mango', 'lemon'] # list of fruits +vegetables = ['Tomato', 'Potato', 'Cabbage','Onion', 'Carrot'] # list of vegetables +animal_products = ['milk', 'meat', 'butter', 'yoghurt'] # list of animal products +web_techs = ['HTML', 'CSS', 'JS', 'React','Redux', 'Node', 'MongDB'] # list of web technologies +countries = ['Finland', 'Estonia', 'Denmark', 'Sweden', 'Norway'] + +# Print the lists and its length +print('Fruits:', fruits) +print('Number of fruits:', len(fruits)) +print('Vegetables:', vegetables) +print('Number of vegetables:', len(vegetables)) +print('Animal products:',animal_products) +print('Number of animal products:', len(animal_products)) +print('Web technologies:', web_techs) +print('Number of web technologies:', len(web_techs)) +print('Countries:', countries) +print('Number of countries:', len(countries)) +``` + +```sh +output +Fruits: ['banana', 'orange', 'mango', 'lemon'] +Number of fruits: 4 +Vegetables: ['Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot'] +Number of vegetables: 5 +Animal products: ['milk', 'meat', 'butter', 'yoghurt'] +Number of animal products: 4 +Web technologies: ['HTML', 'CSS', 'JS', 'React', 'Redux', 'Node', 'MongDB'] +Number of web technologies: 7 +Countries: ['Finland', 'Estonia', 'Denmark', 'Sweden', 'Norway'] +Number of countries: 5 +``` + +- ๋ฆฌ์ŠคํŠธ๋Š” ์„œ๋กœ ๋‹ค๋ฅธ ์ž๋ฃŒํ˜•์˜ ์•„์ดํ…œ์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +```py + lst = ['Asabeneh', 250, True, {'country':'Finland', 'city':'Helsinki'}] # ๋‹ค๋ฅธ ์ž๋ฃŒํ˜•์„ ๊ฐ€์ง„ ๋ฆฌ์ŠคํŠธ +``` + +### Accessing List Items Using Positive Indexing + +์ธ๋ฑ์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ์˜ ๊ฐ ์•„์ดํ…œ์— ์•ก์„ธ์Šคํ•ฉ๋‹ˆ๋‹ค. ๋ฆฌ์ŠคํŠธ ์ธ๋ฑ์Šค๋Š” 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ๊ทธ๋ฆผ์€ ์ธ๋ฑ์Šค๊ฐ€ ์‹œ์ž‘๋˜๋Š” ์œ„์น˜๋ฅผ ๋ช…ํ™•ํ•˜๊ฒŒ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. +![List index](../../images/list_index.png) + +```py +fruits = ['banana', 'orange', 'mango', 'lemon'] +first_fruit = fruits[0] # ์ธ๋ฑ์Šค๋ฅผ ์‚ฌ์šฉํ•ด ์ฒซ๋ฒˆ์งธ ์•„์ดํ…œ์— ์ ‘๊ทผํ•ฉ๋‹ˆ๋‹ค +print(first_fruit) # banana +second_fruit = fruits[1] +print(second_fruit) # orange +last_fruit = fruits[3] +print(last_fruit) # lemon +# Last index +last_index = len(fruits) - 1 +last_fruit = fruits[last_index] +``` + +### Accessing List Items Using Negative Indexing + +์Œ์ˆ˜ ์ธ๋ฑ์Šค๋Š” ๋์—์„œ ์‹œ์ž‘ํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•˜๋ฉฐ -1์€ ๋งˆ์ง€๋ง‰ ์•„์ดํ…œ์„, -2๋Š” ๋งˆ์ง€๋ง‰์—์„œ ๋‘๋ฒˆ์จฐ ์•„์ดํ…œ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. + +![List negative indexing](../../images/list_negative_indexing.png) + +```py +fruits = ['banana', 'orange', 'mango', 'lemon'] +first_fruit = fruits[-4] +last_fruit = fruits[-1] +second_last = fruits[-2] +print(first_fruit) # banana +print(last_fruit) # lemon +print(second_last) # mango +``` + +### Unpacking List Items + +```py +lst = ['item','item2','item3', 'item4', 'item5'] +first_item, second_item, third_item, *rest = lst +print(first_item) # item1 +print(second_item) # item2 +print(third_item) # item3 +print(rest) # ['item4', 'item5'] + +``` + +```py +# First Example +fruits = ['banana', 'orange', 'mango', 'lemon','lime','apple'] +first_fruit, second_fruit, third_fruit, *rest = lst +print(first_fruit) # banana +print(second_fruit) # orange +print(third_fruit) # mango +print(rest) # ['lemon','lime','apple'] +# Second Example about unpacking list +first, second, third,*rest, tenth = [1,2,3,4,5,6,7,8,9,10] +print(first) # 1 +print(second) # 2 +print(third) # 3 +print(rest) # [4,5,6,7,8,9] +print(tenth) # 10 +# Third Example about unpacking list +countries = ['Germany', 'France','Belgium','Sweden','Denmark','Finland','Norway','Iceland','Estonia'] +gr, fr, bg, sw, *scandic, es = countries +print(gr) +print(fr) +print(bg) +print(sw) +print(scandic) +print(es) +``` + +### Slicing Items from a List + +- ์–‘์ˆ˜ ์ธ๋ฑ์‹ฑ: start, end ๋ฐ step์„ ์ง€์ •ํ•˜์—ฌ ์–‘์ˆ˜ ์ธ๋ฑ์Šค ๋ฒ”์œ„๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฐ˜ํ™˜ ๊ฐ’์€ ์ƒˆ ๋ฆฌ์ŠคํŠธ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. (start์˜ ๋””ํดํŠธ๊ฐ’ = 0, end = len(lst) - 1 (๋งˆ์ง€๋ง‰ ์•„์ดํ…œ), step = 1) + +```py +fruits = ['banana', 'orange', 'mango', 'lemon'] +all_fruits = fruits[0:4] # ๋ชจ๋“  fruits๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค +# ์ด๊ฒƒ๋˜ํ•œ ์œ„์™€ ๊ฐ™์€ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค +all_fruits = fruits[0:] # ์šฐ๋ฆฌ๊ฐ€ ์–ด๋””์„œ ๋ฉˆ์ถœ ์ง€ ์„ค์ •ํ•˜์ง€ ์•Š์œผ๋ฉด, ๋ชจ๋“  ๊ฒƒ์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค +orange_and_mango = fruits[1:3] # ์ฒซ๋ฒˆ์งธ ์ธ๋ฑ์Šค๋ฅผ ํฌํ•จํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค +orange_mango_lemon = fruits[1:] +orange_and_lemon = fruits[::2] # ์—ฌ๊ธฐ์„œ ์„ธ๋ฒˆ์งธ ์ธ์ž์ธ step์„ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค. ๋ชจ๋“  ๋‘๋ฒˆ์งธ ์•„์ดํ…œ์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค - ['banana', 'mango'] +``` + +- ์Œ์ˆ˜ ์ธ๋ฑ์‹ฑ: start, end ๋ฐ step์„ ์ง€์ •ํ•˜์—ฌ ์Œ์ˆ˜ ์ธ๋ฑ์Šค์˜ ๋ฒ”์œ„๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฐ˜ํ™˜ ๊ฐ’์€ ์ƒˆ ๋ฆฌ์ŠคํŠธ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. + +```py +fruits = ['banana', 'orange', 'mango', 'lemon'] +all_fruits = fruits[-4:] # ๋ชจ๋“  fruits๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค +orange_and_mango = fruits[-3:-1] # ๋งˆ์ง€๋ง‰ ์ธ๋ฑ์Šค๋ฅผ ํฌํ•จํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค,['orange', 'mango'] +orange_mango_lemon = fruits[-3:] # ์ด๊ฒƒ์€ -3 ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์—ฌ ๋๊นŒ์ง€์˜ ๊ฐ’์„ ์ค๋‹ˆ๋‹ค,['orange', 'mango', 'lemon'] +reverse_fruits = fruits[::-1] # ์Œ์ˆ˜์˜ step์€ ๋ฆฌ์ŠคํŠธ๋ฅผ ์—ญ์ˆœ์œผ๋กœ ๊ฐ€์ง‘๋‹ˆ๋‹ค,['lemon', 'mango', 'orange', 'banana'] +``` + +### Modifying Lists + +๋ฆฌ์ŠคํŠธ๋Š” ๋ณ€๊ฒฝ ๊ฐ€๋Šฅํ•˜๊ฑฐ๋‚˜ ์ˆ˜์ • ๊ฐ€๋Šฅํ•œ ์ˆœ์„œ๊ฐ€ ์žˆ๋Š” ์•„์ดํ…œ๋“ค์˜ ์ปฌ๋ ‰์…˜์ž…๋‹ˆ๋‹ค. ๊ณผ์ผ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ˆ˜์ •ํ•ด๋ด…์‹œ๋‹ค. + +```py +fruits = ['banana', 'orange', 'mango', 'lemon'] +fruits[0] = 'avocado' +print(fruits) # ['avocado', 'orange', 'mango', 'lemon'] +fruits[1] = 'apple' +print(fruits) # ['avocado', 'apple', 'mango', 'lemon'] +last_index = len(fruits) - 1 +fruits[last_index] = 'lime' +print(fruits) # ['avocado', 'apple', 'mango', 'lime'] +``` + +### Checking Items in a List + +*in* ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์•„์ดํ…œ์ด ๋ฆฌ์ŠคํŠธ์˜ ๊ตฌ์„ฑ์›์ธ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ์˜ˆ์‹œ๋ฅผ ๋ด…์‹œ๋‹ค. + +```py +fruits = ['banana', 'orange', 'mango', 'lemon'] +does_exist = 'banana' in fruits +print(does_exist) # True +does_exist = 'lime' in fruits +print(does_exist) # False +``` + +### Adding Items to a List + +๊ธฐ์กด ๋ฆฌ์ŠคํŠธ์˜ ๋์— ์•„์ดํ…œ์„ ์ถ”๊ฐ€ํ•˜๋ ค๋ฉด *append()* ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +```py +# syntax +lst = list() +lst.append(item) +``` + +```py +fruits = ['banana', 'orange', 'mango', 'lemon'] +fruits.append('apple') +print(fruits) # ['banana', 'orange', 'mango', 'lemon', 'apple'] +fruits.append('lime') # ['banana', 'orange', 'mango', 'lemon', 'apple', 'lime'] +print(fruits) +``` + +### Inserting Items into a List + +*insert()* ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชฉ๋ก์˜ ์ง€์ •๋œ ์ธ๋ฑ์Šค์— ํ•˜๋‚˜์˜ ์•„์ดํ…œ์„ ์‚ฝ์ž…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์•„์ดํ…œ๋“ค์€ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ด๋™ํ•œ๋‹ค๋Š” ๊ฒƒ์— ์ฃผ์˜ํ•ฉ์‹œ๋‹ค. *insert()* ๋ฉ”์„œ๋“œ๋Š” ์ธ๋ฑ์Šค์™€ ์‚ฝ์ž…ํ•  ์•„์ดํ…œ์ด๋ผ๋Š” ๋‘ ๊ฐ€์ง€ ์ธ์ž๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค. + +```py +# syntax +lst = ['item1', 'item2'] +lst.insert(index, item) +``` + +```py +fruits = ['banana', 'orange', 'mango', 'lemon'] +fruits.insert(2, 'apple') # orange์™€ mango ์‚ฌ์ด์— apple์„ ์‚ฝ์ž… +print(fruits) # ['banana', 'orange', 'apple', 'mango', 'lemon'] +fruits.insert(3, 'lime') # ['banana', 'orange', 'apple', 'lime', 'mango', 'lemon'] +print(fruits) +``` + +### Removing Items from a List + +remove ๋ฉ”์„œ๋“œ๋Š” ๋ฆฌ์ŠคํŠธ์—์„œ ์ง€์ •๋œ ์•„์ดํ…œ์„ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค. + +```py +# syntax +lst = ['item1', 'item2'] +lst.remove(item) +``` + +```py +fruits = ['banana', 'orange', 'mango', 'lemon', 'banana'] +fruits.remove('banana') +print(fruits) # ['orange', 'mango', 'lemon', 'banana'] - ์ด ๋ฉ”์„œ๋“œ๋Š” ๋ฆฌ์ŠคํŠธ์—์„œ ์ฒซ๋ฒˆ์งธ๋กœ ์กด์žฌํ•˜๋Š” ์•„์ดํ…œ์„ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค +fruits.remove('lemon') +print(fruits) # ['orange', 'mango', 'banana'] +``` + +### Removing Items Using Pop + +*pop()* ๋ฉ”์„œ๋“œ๋Š” ์ง€์ •๋œ ์ธ๋ฑ์Šค๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค(๋˜๋Š” ์ธ๋ฑ์Šค๊ฐ€ ์ง€์ •๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ๋งˆ์ง€๋ง‰ ์•„์ดํ…œ): + +```py +# syntax +lst = ['item1', 'item2'] +lst.pop() # ๋งˆ์ง€๋ง‰ ์•„์ดํ…œ +lst.pop(index) +``` + +```py +fruits = ['banana', 'orange', 'mango', 'lemon'] +fruits.pop() +print(fruits) # ['banana', 'orange', 'mango'] + +fruits.pop(0) +print(fruits) # ['orange', 'mango'] +``` + +### Removing Items Using Del + +*del* ํ‚ค์›Œ๋“œ๋Š” ์ง€์ •๋œ ์ธ๋ฑ์Šค๋ฅผ ์‚ญ์ œํ•˜๋ฉฐ ์ธ๋ฑ์Šค ๋ฒ”์œ„ ๋‚ด์˜ ์•„์ดํ…œ์„ ์‚ญ์ œํ•˜๋Š” ๋ฐ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ ๋ฆฌ์ŠคํŠธ๋ฅผ ์™„์ „ํžˆ ์‚ญ์ œํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. + +```py +# syntax +lst = ['item1', 'item2'] +del lst[index] # ํ•˜๋‹ˆ์˜ ์•„์ดํ…œ +del lst # ๋ฆฌ์ŠคํŠธ๋ฅผ ์™„์ „ํžˆ ์‚ญ์ œ +``` + +```py +fruits = ['banana', 'orange', 'mango', 'lemon', 'kiwi', 'lime'] +del fruits[0] +print(fruits) # ['orange', 'mango', 'lemon', 'kiwi', 'lime'] +del fruits[1] +print(fruits) # ['orange', 'lemon', 'kiwi', 'lime'] +del fruits[1:3] # ์ด๊ฒƒ์€ ์ฃผ์–ด์ง„ ์ธ๋ฑ์Šค ์‚ฌ์ด์˜ ์•„์ดํ…œ์„ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค, ๊ทธ๋Ÿฌ๋ฏ€๋กœ ์ธ๋ฑ์Šค๊ฐ€ 3์ธ ์•„์ดํ…œ์€ ์‚ญ์ œ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค! +print(fruits) # ['orange', 'lime'] +del fruits +print(fruits) # NameError: name 'fruits' is not defined ๊ฐ€ ๋ฐœ์ƒํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค +``` + +### Clearing List Items + +*clear()* ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด ๋ฆฌ์ŠคํŠธ ๋น„์šฐ๊ธฐ: + +```py +# syntax +lst = ['item1', 'item2'] +lst.clear() +``` + +```py +fruits = ['banana', 'orange', 'mango', 'lemon'] +fruits.clear() +print(fruits) # [] +``` + +### Copying a List + +๋‹ค์Œ์˜ ๋ฐฉ๋ฒ•์œผ๋กœ ์ƒˆ ๋ณ€์ˆ˜์— ์žฌํ• ๋‹นํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ณต์‚ฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:list2 = list1. ์ด์ œ list2๋Š” list1์˜ ์ฐธ์กฐ์ด๋ฉฐ, list2์—์„œ ๋ณ€๊ฒฝํ•œ ๋‚ด์šฉ์€ ์›๋ณธ list1๋„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์›๋ณธ์„ ์ˆ˜์ •ํ•˜๊ณ  ์‹ถ์ง€ ์•Š๊ณ  ๋‹ค๋ฅธ ์‚ฌ๋ณธ์„ ๊ฐ–๊ณ  ์‹ถ์–ดํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์Šต๋‹ˆ๋‹ค. ์œ„์˜ ๋ฌธ์ œ๋ฅผ ํ”ผํ•˜๋Š” ํ•œ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์€ _copy()_ ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. + +```py +# syntax +lst = ['item1', 'item2'] +lst_copy = lst.copy() +``` + +```py +fruits = ['banana', 'orange', 'mango', 'lemon'] +fruits_copy = fruits.copy() +print(fruits_copy) # ['banana', 'orange', 'mango', 'lemon'] +``` + +### Joining Lists + +ํŒŒ์ด์ฌ์—์„œ ๋‘ ๊ฐœ ์ด์ƒ์˜ ๋ชฉ๋ก์„ ๊ฒฐํ•ฉํ•˜๊ฑฐ๋‚˜ ์—ฐ๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์—ฌ๋Ÿฌ ๊ฐ€์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. + +- ํ”Œ๋Ÿฌ์Šค ์—ฐ์‚ฐ์ž (+) + +```py +# syntax +list3 = list1 + list2 +``` + +```py +positive_numbers = [1, 2, 3, 4, 5] +zero = [0] +negative_numbers = [-5,-4,-3,-2,-1] +integers = negative_numbers + zero + positive_numbers +print(integers) # [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5] +fruits = ['banana', 'orange', 'mango', 'lemon'] +vegetables = ['Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot'] +fruits_and_vegetables = fruits + vegetables +print(fruits_and_vegetables ) # ['banana', 'orange', 'mango', 'lemon', 'Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot'] +``` + +- extend() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ฐ๊ฒฐ + *extend()* ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฆฌ์ŠคํŠธ์— ๋ฆฌ์ŠคํŠธ๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜ ์˜ˆ๋ฅผ ์ฐธ์กฐํ•ฉ์‹œ๋‹ค. + +```py +# syntax +list1 = ['item1', 'item2'] +list2 = ['item3', 'item4', 'item5'] +list1.extend(list2) +``` + +```py +num1 = [0, 1, 2, 3] +num2= [4, 5, 6] +num1.extend(num2) +print('Numbers:', num1) # Numbers: [0, 1, 2, 3, 4, 5, 6] +negative_numbers = [-5,-4,-3,-2,-1] +positive_numbers = [1, 2, 3,4,5] +zero = [0] + +negative_numbers.extend(zero) +negative_numbers.extend(positive_numbers) +print('Integers:', negative_numbers) # Integers: [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5] +fruits = ['banana', 'orange', 'mango', 'lemon'] +vegetables = ['Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot'] +fruits.extend(vegetables) +print('Fruits and vegetables:', fruits ) # Fruits and vegetables: ['banana', 'orange', 'mango', 'lemon', 'Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot'] +``` + +### Counting Items in a List + +*count()* ๋ฉ”์„œ๋“œ๋Š” ๋ฆฌ์ŠคํŠธ์— ์•„์ดํ…œ์ด ๋‚˜ํƒ€๋‚˜๋Š” ํšŸ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค: + +```py +# syntax +lst = ['item1', 'item2'] +lst.count(item) +``` + +```py +fruits = ['banana', 'orange', 'mango', 'lemon'] +print(fruits.count('orange')) # 1 +ages = [22, 19, 24, 25, 26, 24, 25, 24] +print(ages.count(24)) # 3 +``` + +### Finding Index of an Item + +*index()* ๋ฉ”์„œ๋“œ๋Š” ๋ฆฌ์ŠคํŠธ์— ์žˆ๋Š” ์•„์ดํ…œ์˜ ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค: + +```py +# syntax +lst = ['item1', 'item2'] +lst.index(item) +``` + +```py +fruits = ['banana', 'orange', 'mango', 'lemon'] +print(fruits.index('orange')) # 1 +ages = [22, 19, 24, 25, 26, 24, 25, 24] +print(ages.index(24)) # 2, ์ฒ˜์Œ ๋งŒ๋‚œ ๊ฒƒ +``` + +### Reversing a List + +*reverse()* ๋ฉ”์„œ๋“œ๋Š” ๋ฆฌ์ŠคํŠธ์˜ ์ˆœ์„œ๋ฅผ ๊ฑฐ๊พธ๋กœ ํ•ฉ๋‹ˆ๋‹ค. + +```py +# syntax +lst = ['item1', 'item2'] +lst.reverse() + +``` + +```py +fruits = ['banana', 'orange', 'mango', 'lemon'] +fruits.reverse() +print(fruits) # ['lemon', 'mango', 'orange', 'banana'] +ages = [22, 19, 24, 25, 26, 24, 25, 24] +ages.reverse() +print(ages) # [24, 25, 24, 26, 25, 24, 19, 22] +``` + +### Sorting List Items + +๋ฆฌ์ŠคํŠธ๋ฅผ ์ •๋ ฌํ•˜๋ ค๋ฉด _sort()_ ๋ฉ”์„œ๋“œ ๋˜๋Š” _sorted()_ ๋‚ด์žฅ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. _sort()_ ๋ฉ”์„œ๋“œ๋Š” ๋ฆฌ์ŠคํŠธ ์•„์ดํ…œ์„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๊ณ  ์›๋ž˜ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ _sort()_ ๋ฉ”์„œ๋“œ์˜ reverse์˜ ์ธ์ž๊ฐ€ true๋ผ๋ฉด, ๊ทธ๊ฒƒ์€ ๋ชฉ๋ก์„ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ๋ฐฐ์—ดํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค. + +- sort(): ์ด ๋ฉ”์„œ๋“œ๋Š” ์›๋ž˜ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค + + ```py + # syntax + lst = ['item1', 'item2'] + lst.sort() # ์˜ค๋ฆ„์ฐจ์ˆœ + lst.sort(reverse=True) # ๋‚ด๋ฆผ์ฐจ์ˆœ + ``` + + **Example:** + + ```py + fruits = ['banana', 'orange', 'mango', 'lemon'] + fruits.sort() + print(fruits) # ์•ŒํŒŒ๋ฒณ์ˆœ์œผ๋กœ ์ •๋ ฌ, ['banana', 'lemon', 'mango', 'orange'] + fruits.sort(reverse=True) + print(fruits) # ['orange', 'mango', 'lemon', 'banana'] + ages = [22, 19, 24, 25, 26, 24, 25, 24] + ages.sort() + print(ages) # [19, 22, 24, 24, 24, 25, 25, 26] + + ages.sort(reverse=True) + print(ages) # [26, 25, 25, 24, 24, 24, 22, 19] + ``` + + sorted(): ์›๋ž˜ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ˆ˜์ •ํ•˜์ง€ ์•Š๊ณ  ์ •๋ ฌ๋œ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค + **Example:** + + ```py + fruits = ['banana', 'orange', 'mango', 'lemon'] + print(sorted(fruits)) # ['banana', 'lemon', 'mango', 'orange'] + # ์—ญ์ˆœ + fruits = ['banana', 'orange', 'mango', 'lemon'] + fruits = sorted(fruits,reverse=True) + print(fruits) # ['orange', 'mango', 'lemon', 'banana'] + ``` + +๐ŸŒ• ๋‹น์‹ ์€ ์„ฑ์‹คํ•˜๊ณ  ์ด๋ฏธ ๋งŽ์€ ๊ฒƒ์„ ์„ฑ์ทจํ–ˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ๋ถ„์€ ์ด์ œ ๋ง‰ 5์ผ์ฐจ ๋„์ „์„ ๋งˆ์ณค๊ณ  ์œ„๋Œ€ํ•จ์„ ํ–ฅํ•œ 5๊ฑธ์Œ ์•ž์— ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ ์—ฌ๋Ÿฌ๋ถ„์˜ ๋‡Œ์™€ ๊ทผ์œก์„ ์œ„ํ•œ ์šด๋™์„ ํ•˜์„ธ์š”. + +## ๐Ÿ’ป Exercises: Day 5 + +### Exercises: Level 1 + +1. ๋นˆ ๋ฆฌ์ŠคํŠธ๋ฅผ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค +2. 5๊ฐœ ์ด์ƒ์˜ ์•„์ดํ…œ์„ ๊ฐ–๋Š” ๋ฆฌ์ŠคํŠธ๋ฅผ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค +3. ๋‹น์‹ ์˜ ๋ฆฌ์ŠคํŠธ์˜ ๊ธธ์ด๋ฅผ ์•Œ์•„๋ด…๋‹ˆ๋‹ค +4. ๋ฆฌ์ŠคํŠธ์˜ ์ฒซ๋ฒˆ์งธ, ์ค‘๊ฐ„์˜, ๋งˆ์ง€๋ง‰ ์•„์ดํ…œ์„ ์–ป์–ด๋ด…๋‹ˆ๋‹ค +5. mixed_data_types ๋ผ๋Š” ๋ฆฌ์ŠคํŠธ๋ฅผ ์„ ์–ธํ•˜๊ณ , ๋‹น์‹ ์˜ ์ด๋ฆ„, ๋‚˜์ด, ํ‚ค, ๊ฒฐํ˜ผ ์—ฌ๋ถ€, ์ฃผ์†Œ๋ฅผ ๋„ฃ์–ด๋ด…์‹œ๋‹ค +6. it_companies ๋ผ๋Š” ์ด๋ฆ„์˜ ๋ชฉ๋ก ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ์ดˆ๊ธฐ ๊ฐ’์— Facebook, Google, Microsoft, Apple, IBM, Oracle ๋ฐ Amazon์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค +7. _print()_ ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ๋ฅผ ํ”„๋ฆฐํŠธ ํ•ฉ๋‹ˆ๋‹ค +8. ๋ฆฌ์ŠคํŠธ์— ์žˆ๋Š” ๊ธฐ์—… ์ˆ˜๋ฅผ ํ”„๋ฆฐํŠธ ํ•ฉ๋‹ˆ๋‹ค +9. ์ฒซ๋ฒˆ์งธ, ์ค‘๊ฐ„, ๋งˆ์ง€๋ง‰ ๊ธฐ์—…์„ ํ”„๋ฆฐํŠธ ํ•ฉ๋‹ˆ๋‹ค +10. ๊ธฐ์—… ์ค‘ ํ•˜๋‚˜๋ฅผ ์ˆ˜์ •ํ•˜๊ณ  ๋ฆฌ์ŠคํŠธ๋ฅผ ํ”„๋ฆฐํŠธ ํ•ฉ๋‹ˆ๋‹ค +11. it_companies ์— ํ•˜๋‚˜์˜ IT ๊ธฐ์—…์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค +12. ํšŒ์‚ฌ ๋ฆฌ์ŠคํŠธ ์ค‘๊ฐ„์— IT ๊ธฐ์—…์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค +13. it_companies ์ด๋ฆ„ ์ค‘ ํ•˜๋‚˜๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค (IBM ์ œ์™ธ!) +14. '#;  ' ๋ผ๋Š” ๋ฌธ์ž์—ด๋กœ it_companies ์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค +15. it_companies ๋ฆฌ์ŠคํŠธ์— ํŠน์ • ๊ธฐ์—…์ด ์กด์žฌํ•˜๋Š” ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค +16. sort() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด ๋ฆฌ์ŠคํŠธ๋ฅผ ์ •๋ ฌํ•ฉ๋‹ˆ๋‹ค +17. reverse() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ๋ฐ˜์ „ํ•ฉ๋‹ˆ๋‹ค +18. ๋ฆฌ์ŠคํŠธ์—์„œ ์ฒ˜์Œ 3๊ฐœ์˜ ๊ธฐ์—…์„ ์ž˜๋ผ๋ƒ…๋‹ˆ๋‹ค +19. ๋ฆฌ์ŠคํŠธ์—์„œ ๋งˆ์ง€๋ง‰ 3๊ฐœ์˜ ๊ธฐ์—…์„ ์ž˜๋ผ๋ƒ…๋‹ˆ๋‹ค +20. ๋ฆฌ์ŠคํŠธ์—์„œ ์ค‘๊ฐ„์˜ IT ๊ธฐ์—… ๋˜๋Š” ๊ธฐ์—…๋“ค์„ ์ž˜๋ผ๋ƒ…๋‹ˆ๋‹ค +21. ๋ฆฌ์ŠคํŠธ์—์„œ ์ฒซ๋ฒˆ์งธ IT ๊ธฐ์—…์„ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค +22. ๋ฆฌ์ŠคํŠธ์—์„œ ์ค‘๊ฐ„์˜ IT ๊ธฐ์—… ๋˜๋Š” ๊ธฐ์—…๋“ค์„ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค +23. ๋ฆฌ์ŠคํŠธ์—์„œ ๋งˆ์ง€๋ง‰ IT ๊ธฐ์—…์„ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค +24. ๋ฆฌ์ŠคํŠธ์—์„œ ๋ชจ๋“  IT ๊ธฐ์—…์„ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค +25. IT ๊ธฐ์—… ๋ฆฌ์ŠคํŠธ๋ฅผ ์™„์ „ํžˆ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค +26. ๋‹ค์Œ ๋ฆฌ์ŠคํŠธ๋ฅผ ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค: + + ```py + front_end = ['HTML', 'CSS', 'JS', 'React', 'Redux'] + back_end = ['Node','Express', 'MongoDB'] + ``` + +27. 26๋ฒˆ ๋ฌธ์ œ์˜ ๋ฆฌ์ŠคํŠธ๋ฅผ ์—ฐ๊ฒฐํ•œ ํ›„, ์—ฐ๊ฒฐ๋œ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ณต์‚ฌํ•ด full_stack ๋ณ€์ˆ˜์— ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  Python, SQL, Redux๋ฅผ ์‚ฝ์ž…ํ•ฉ๋‹ˆ๋‹ค. + +### Exercises: Level 2 + +1. ๋‹ค์Œ์€ 10๋ช…์˜ ํ•™์ƒ์˜ ๋‚˜์ด ๋ฆฌ์ŠคํŠธ์ž…๋‹ˆ๋‹ค: + +```sh +ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24] +``` + +- ๋ฆฌ์ŠคํŠธ๋ฅผ ์ •๋ ฌํ•˜๊ณ  ์ตœ์†Œ๊ฐ’ ๋ฐ ์ตœ๋Œ€๊ฐ’ ์ฐพ์Šต๋‹ˆ๋‹ค +- ๋ฆฌ์ŠคํŠธ์— ์ตœ์†Œ๊ฐ’ ๋ฐ ์ตœ๋Œ€๊ฐ’์„ ๋‹ค์‹œ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค +- ๋‚˜์ด์˜ ์ค‘์œ„๊ฐ’์„ ์ฐพ์Šต๋‹ˆ๋‹ค(์ค‘๊ฐ„ ์•„์ดํ…œ ํ•˜๋‚˜ ๋˜๋Š” ์ค‘๊ฐ„ ์•„์ดํ…œ ๋‘ ๊ฐœ๋ฅผ 2๋กœ ๋‚˜๋ˆˆ ๊ฐ’) +- ํ‰๊ท  ๋‚˜์ด๋ฅผ ๊ตฌํ•ฉ๋‹ˆ๋‹ค(๋ชจ๋“  ์•„์ดํ…œ์˜ ํ•ฉ์„ ๊ฐœ์ˆ˜๋กœ ๋‚˜๋ˆˆ ๊ฐ’) +- ๋‚˜์ด์˜ ๋ฒ”์œ„๋ฅผ ๊ตฌํ•ฉ๋‹ˆ๋‹ค(์ตœ๋Œ€๊ฐ’ ๋นผ๊ธฐ ์ตœ์†Œ๊ฐ’) +- (์ตœ์†Œ๊ฐ’ - ํ‰๊ท )๊ณผ (์ตœ๋Œ€๊ฐ’ - ํ‰๊ท )์˜ ๊ฐ’์„ ๋น„๊ตํ•˜๊ณ  _abs()_ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +1. [๊ตญ๊ฐ€ ๋ชฉ๋ก](https://github.com/Asabeneh/30-Days-Of-Python/tree/master/data/countries.py) ์—์„œ ์ค‘๊ฐ„ ๊ตญ๊ฐ€๋ฅผ ์ฐพ์Šต๋‹ˆ๋‹ค. +1. ๊ตญ๊ฐ€ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋‘๊ฐœ์˜ ๋ฆฌ์ŠคํŠธ๋กœ ๋‚˜๋ˆ•๋‹ˆ๋‹ค. ์ง์ˆ˜๋ผ๋ฉด ๋‘๊ฐœ์˜ ๋ฆฌ์ŠคํŠธ์˜ ํฌ๊ธฐ๊ฐ€ ๊ฐ–๊ฒŒ, ์•„๋‹ˆ๋ผ๋ฉด ์•ž์˜ ๋ฆฌ์ŠคํŠธ๊ฐ€ ํ•˜๋‚˜์˜ ๊ตญ๊ฐ€๋ฅผ ๋” ๊ฐ–๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. +1. ['China', 'Russia', 'USA', 'Finland', 'Sweden', 'Norway', 'Denmark']. ์•ž์˜ ์„ธ๊ฐœ ๊ตญ๊ฐ€์™€ ๋‚˜๋จธ์ง€๋ฅผ scandic countries๋กœ unpackํ•ฉ๋‹ˆ๋‹ค. + +๐ŸŽ‰ CONGRATULATIONS ! ๐ŸŽ‰ + +[<< Day 4](../04_Day_Strings/04_strings.md) | [Day 6 >>](../06_Day_Tuples/06_tuples.md) From ec87e0da4204856c042fa6c0397b49563556f5e6 Mon Sep 17 00:00:00 2001 From: ShinYooJung Date: Fri, 9 Dec 2022 14:44:05 +0900 Subject: [PATCH 20/21] Typo error --- 05_Day_Lists/05_lists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/05_Day_Lists/05_lists.md b/05_Day_Lists/05_lists.md index ac18fce3..b3fb49f6 100644 --- a/05_Day_Lists/05_lists.md +++ b/05_Day_Lists/05_lists.md @@ -364,7 +364,7 @@ print(fruits) # [] ### Copying a List -It is possible to copy a list by reassigning it to a new variable in the following way: list2 = list1. Now, list2 is a reference of list1, any changes we make in list2 will also modify the original, list2. But there are lots of case in which we do not like to modify the original instead we like to have a different copy. One of way of avoiding the problem above is using _copy()_. +It is possible to copy a list by reassigning it to a new variable in the following way: list2 = list1. Now, list2 is a reference of list1, any changes we make in list2 will also modify the original, list1. But there are lots of case in which we do not like to modify the original instead we like to have a different copy. One of way of avoiding the problem above is using _copy()_. ```py # syntax From ab25567784961fc4ca7c80c20f6c287385173ffa Mon Sep 17 00:00:00 2001 From: ShinYooJung Date: Fri, 9 Dec 2022 15:08:05 +0900 Subject: [PATCH 21/21] Add Day 8 Korean Translation --- Korean/08_Day_Dictionaries/08_dictionaries.md | 342 ++++++++++++++++++ 1 file changed, 342 insertions(+) create mode 100644 Korean/08_Day_Dictionaries/08_dictionaries.md diff --git a/Korean/08_Day_Dictionaries/08_dictionaries.md b/Korean/08_Day_Dictionaries/08_dictionaries.md new file mode 100644 index 00000000..a418cac2 --- /dev/null +++ b/Korean/08_Day_Dictionaries/08_dictionaries.md @@ -0,0 +1,342 @@ +
+

30 Days Of Python: Day 8 - Dictionaries

+ + + + + Twitter Follow + + +Author: +Asabeneh Yetayeh
+ Second Edition: July, 2021 +
+ +
+ +[<< Day 7 ](../07_Day_Sets/07_sets.md) | [Day 9 >>](../09_Day_Conditionals/09_conditionals.md) + +![30DaysOfPython](../../images/30DaysOfPython_banner3@2x.png) + +- [๐Ÿ“˜ Day 8](#-day-8) + - [Dictionaries](#dictionaries) + - [Creating a Dictionary](#creating-a-dictionary) + - [Dictionary Length](#dictionary-length) + - [Accessing Dictionary Items](#accessing-dictionary-items) + - [Adding Items to a Dictionary](#adding-items-to-a-dictionary) + - [Modifying Items in a Dictionary](#modifying-items-in-a-dictionary) + - [Checking Keys in a Dictionary](#checking-keys-in-a-dictionary) + - [Removing Key and Value Pairs from a Dictionary](#removing-key-and-value-pairs-from-a-dictionary) + - [Changing Dictionary to a List of Items](#changing-dictionary-to-a-list-of-items) + - [Clearing a Dictionary](#clearing-a-dictionary) + - [Deleting a Dictionary](#deleting-a-dictionary) + - [Copy a Dictionary](#copy-a-dictionary) + - [Getting Dictionary Keys as a List](#getting-dictionary-keys-as-a-list) + - [Getting Dictionary Values as a List](#getting-dictionary-values-as-a-list) + - [๐Ÿ’ป Exercises: Day 8](#-exercises-day-8) + +# ๐Ÿ“˜ Day 8 + +## Dictionaries + +Dictionary๋Š” ์ˆœ์„œ๊ฐ€ ์—†๋Š” ์ˆ˜์ •(๋ณ€ํ˜•) ๊ฐ€๋Šฅํ•œ ์Œ(ํ‚ค: ๊ฐ’)์˜ ์ž๋ฃŒํ˜•์˜ ์ปฌ๋ ‰์…˜์ž…๋‹ˆ๋‹ค. + +### Creating a Dictionary + +Dictionary๋ฅผ ๋งŒ๋“ค๋ ค๋ฉด ์ค‘๊ด„ํ˜ธ {} ๋˜๋Š” *dict()* ๋‚ด์žฅ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +```py +# syntax +empty_dict = {} +# Dictionary with data values +dct = {'key1':'value1', 'key2':'value2', 'key3':'value3', 'key4':'value4'} +``` + +**Example:** + +```py +person = { + 'first_name':'Asabeneh', + 'last_name':'Yetayeh', + 'age':250, + 'country':'Finland', + 'is_marred':True, + 'skills':['JavaScript', 'React', 'Node', 'MongoDB', 'Python'], + 'address':{ + 'street':'Space street', + 'zipcode':'02210' + } + } +``` + +์ƒ๋‹จ์˜ Dictionary๋Š” ๊ฐ’์ด ์–ด๋–ค ์ž๋ฃŒํ˜•์ผ ์ˆ˜๋„ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค:string, boolean, list, tuple, set ๋˜๋Š” dictionary. + +### Dictionary Length + +dictionary ๋‚ด 'key: value' ์Œ์˜ ๊ฐœ์ˆ˜๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. + +```py +# syntax +dct = {'key1':'value1', 'key2':'value2', 'key3':'value3', 'key4':'value4'} +print(len(dct)) # 4 +``` + +**Example:** + +```py +person = { + 'first_name':'Asabeneh', + 'last_name':'Yetayeh', + 'age':250, + 'country':'Finland', + 'is_marred':True, + 'skills':['JavaScript', 'React', 'Node', 'MongoDB', 'Python'], + 'address':{ + 'street':'Space street', + 'zipcode':'02210' + } + } +print(len(person)) # 7 + +``` + +### Accessing Dictionary Items + +ํ‚ค์˜ ์ด๋ฆ„์„ ํ†ตํ•ด ๋”•์…”๋„ˆ๋ฆฌ ์•„์ดํ…œ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +```py +# syntax +dct = {'key1':'value1', 'key2':'value2', 'key3':'value3', 'key4':'value4'} +print(dct['key1']) # value1 +print(dct['key4']) # value4 +``` + +**Example:** + +```py +person = { + 'first_name':'Asabeneh', + 'last_name':'Yetayeh', + 'age':250, + 'country':'Finland', + 'is_marred':True, + 'skills':['JavaScript', 'React', 'Node', 'MongoDB', 'Python'], + 'address':{ + 'street':'Space street', + 'zipcode':'02210' + } + } +print(person['first_name']) # Asabeneh +print(person['country']) # Finland +print(person['skills']) # ['JavaScript', 'React', 'Node', 'MongoDB', 'Python'] +print(person['skills'][0]) # JavaScript +print(person['address']['street']) # Space street +print(person['city']) # Error +``` + +์กด์žฌํ•˜์ง€ ์•Š๋Š” ํ‚ค์˜ ์ด๋ฆ„์œผ๋กœ ์•„์ดํ…œ์— ์ ‘๊ทผํ•  ๊ฒฝ์šฐ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ์—๋Ÿฌ๋ฅผ ํ”ผํ•˜๊ธฐ์œ„ํ•ด ์šฐ๋ฆฌ๋Š” ์šฐ์„  ํ‚ค๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. ๋˜๋Š” _get_ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ• ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. get ๋ฉ”์„œ๋“œ๋Š” ํ‚ค๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ, NoneType object ์ž๋ฃŒํ˜•์ธ None์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. +```py +person = { + 'first_name':'Asabeneh', + 'last_name':'Yetayeh', + 'age':250, + 'country':'Finland', + 'is_marred':True, + 'skills':['JavaScript', 'React', 'Node', 'MongoDB', 'Python'], + 'address':{ + 'street':'Space street', + 'zipcode':'02210' + } + } +print(person.get('first_name')) # Asabeneh +print(person.get('country')) # Finland +print(person.get('skills')) #['HTML','CSS','JavaScript', 'React', 'Node', 'MongoDB', 'Python'] +print(person.get('city')) # None +``` + +### Adding Items to a Dictionary + +๋”•์…”๋„ˆ๋ฆฌ์— ์ƒˆ๋กœ์šด ํ‚ค์™€ ๊ฐ’์˜ ์Œ์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +```py +# syntax +dct = {'key1':'value1', 'key2':'value2', 'key3':'value3', 'key4':'value4'} +dct['key5'] = 'value5' +``` + +**Example:** + +```py +person = { + 'first_name':'Asabeneh', + 'last_name':'Yetayeh', + 'age':250, + 'country':'Finland', + 'is_marred':True, + 'skills':['JavaScript', 'React', 'Node', 'MongoDB', 'Python'], + 'address':{ + 'street':'Space street', + 'zipcode':'02210' + } +} +person['job_title'] = 'Instructor' +person['skills'].append('HTML') +print(person) +``` + +### Modifying Items in a Dictionary + +๋”•์…”๋„ˆ๋ฆฌ์˜ ์•„์ดํ…œ์„ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค + +```py +# syntax +dct = {'key1':'value1', 'key2':'value2', 'key3':'value3', 'key4':'value4'} +dct['key1'] = 'value-one' +``` + +**Example:** + +```py +person = { + 'first_name':'Asabeneh', + 'last_name':'Yetayeh', + 'age':250, + 'country':'Finland', + 'is_marred':True, + 'skills':['JavaScript', 'React', 'Node', 'MongoDB', 'Python'], + 'address':{ + 'street':'Space street', + 'zipcode':'02210' + } + } +person['first_name'] = 'Eyob' +person['age'] = 252 +``` + +### Checking Keys in a Dictionary + +๋”•์…”๋„ˆ๋ฆฌ์— ํ‚ค๊ฐ€ ์กด์žฌํ•˜๋Š” ์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด _in_ ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค + +```py +# syntax +dct = {'key1':'value1', 'key2':'value2', 'key3':'value3', 'key4':'value4'} +print('key2' in dct) # True +print('key5' in dct) # False +``` + +### Removing Key and Value Pairs from a Dictionary + +- _pop(key)_: ํŠน์ • ํ‚ค ์ด๋ฆ„์„ ๊ฐ€์ง„ ์•„์ดํ…œ์„ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค +- _popitem()_: ๋งˆ์ง€๋ง‰ ์•„์ดํ…œ์„ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค +- _del_: ํŠน์ • ํ‚ค ์ด๋ฆ„์„ ๊ฐ€์ง„ ์•„์ดํ…œ์„ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค + +```py +# syntax +dct = {'key1':'value1', 'key2':'value2', 'key3':'value3', 'key4':'value4'} +dct.pop('key1') # removes key1 item +dct = {'key1':'value1', 'key2':'value2', 'key3':'value3', 'key4':'value4'} +dct.popitem() # removes the last item +del dct['key2'] # removes key2 item +``` + +**Example:** + +```py +person = { + 'first_name':'Asabeneh', + 'last_name':'Yetayeh', + 'age':250, + 'country':'Finland', + 'is_marred':True, + 'skills':['JavaScript', 'React', 'Node', 'MongoDB', 'Python'], + 'address':{ + 'street':'Space street', + 'zipcode':'02210' + } + } +person.pop('first_name') # Removes the firstname item +person.popitem() # Removes the address item +del person['is_married'] # Removes the is_married item +``` + +### Changing Dictionary to a List of Items + +_items()_ ๋ฉ”์„œ๋“œ๋Š” ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ํŠœํ”Œ์˜ ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค. + +```py +# syntax +dct = {'key1':'value1', 'key2':'value2', 'key3':'value3', 'key4':'value4'} +print(dct.items()) # dict_items([('key1', 'value1'), ('key2', 'value2'), ('key3', 'value3'), ('key4', 'value4')]) +``` + +### Clearing a Dictionary + +๋”•์…”๋„ˆ๋ฆฌ ๋‚ด์˜ ์•„์ดํ…œ์„ ์›ํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด _clear()_ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด ๋น„์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค + +```py +# syntax +dct = {'key1':'value1', 'key2':'value2', 'key3':'value3', 'key4':'value4'} +print(dct.clear()) # None +``` + +### Deleting a Dictionary + +๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์ง€์•Š๋Š”๋‹ค๋ฉด ์™„์ „ํžˆ ์ง€์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค + +```py +# syntax +dct = {'key1':'value1', 'key2':'value2', 'key3':'value3', 'key4':'value4'} +del dct +``` + +### Copy a Dictionary + +_copy()_ ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ๋ณต์‚ฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. copy๋ฅผ ์‚ฌ์šฉํ•ด ์›๋ž˜ ๋”•์…”๋„ˆ๋ฆฌ์˜ ๋ณ€ํ™”๋ฅผ ๋ง‰์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +```py +# syntax +dct = {'key1':'value1', 'key2':'value2', 'key3':'value3', 'key4':'value4'} +dct_copy = dct.copy() # {'key1':'value1', 'key2':'value2', 'key3':'value3', 'key4':'value4'} +``` + +### Getting Dictionary Keys as a List + +_keys()_ ๋ฉ”์„œ๋“œ๋Š” ํ•˜๋‚˜์˜ ๋”•์…”๋„ˆ๋ฆฌ์˜ ๋ชจ๋“  ํ‚ค๋ฅผ ๋ฆฌ์ŠคํŠธ๋กœ ์ค๋‹ˆ๋‹ค. + +```py +# syntax +dct = {'key1':'value1', 'key2':'value2', 'key3':'value3', 'key4':'value4'} +keys = dct.keys() +print(keys) # dict_keys(['key1', 'key2', 'key3', 'key4']) +``` + +### Getting Dictionary Values as a List + +_values_ ๋ฉ”์„œ๋“œ๋Š” ํ•˜๋‚˜์˜ ๋”•์…”๋„ˆ๋ฆฌ์˜ ๋ชจ๋“  ๊ฐ’์„ ๋ฆฌ์ŠคํŠธ๋กœ ์ค๋‹ˆ๋‹ค. + +```py +# syntax +dct = {'key1':'value1', 'key2':'value2', 'key3':'value3', 'key4':'value4'} +values = dct.values() +print(values) # dict_values(['value1', 'value2', 'value3', 'value4']) +``` + +๐ŸŒ• ๋‹น์‹ ์€ ์ •๋ง ๋†€๋ผ์›Œ์š”. ์ด์ œ, ์—ฌ๋Ÿฌ๋ถ„์€ ์‚ฌ์ „์˜ ํž˜์œผ๋กœ ์™„์ „ํžˆ ์ถฉ์ „๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ๋ถ„์€ ์ด์ œ ๋ง‰ 8์ผ์งธ์˜ ๋„์ „์„ ๋งˆ์ณค๊ณ  ์œ„๋Œ€ํ•จ์„ ํ–ฅํ•ด 8๋ณด ์ „์ง„ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ ์—ฌ๋Ÿฌ๋ถ„์˜ ๋‡Œ์™€ ๊ทผ์œก์„ ์œ„ํ•œ ์šด๋™์„ ํ•˜์„ธ์š”. + +## ๐Ÿ’ป Exercises: Day 8 + +1. dog๋ผ๋Š” ์ด๋ฆ„์˜ ๋นˆ ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค +2. dog ๋”•์…”๋„ˆ๋ฆฌ์— name, color, breed, legs, age ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค +3. student ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  first_name, last_name, gender, age, marital status, skills, country, city ์™€ address ๋ฅผ ํ‚ค๋กœ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค +4. student ๋”•์…”๋„ˆ๋ฆฌ์˜ ๊ธธ์ด๋ฅผ ์–ป์Šต๋‹ˆ๋‹ค +5. skills ์˜ ๊ฐ’์„ ์–ป๊ณ  ์ž๋ฃŒํ˜•์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค, list ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค +6. ํ•œ๊ฐœ๋‚˜ ๋‘๊ฐœ๋ฅผ ์ถ”๊ฐ€ํ•ด skills์˜ ๊ฐ’์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค +7. ๋”•์…”๋„ˆ๋ฆฌ์˜ ํ‚ค๋ฅผ ๋ฆฌ์ŠคํŠธ๋กœ ์–ป์Šต๋‹ˆ๋‹ค +8. ๋”•์…”๋„ˆ๋ฆฌ์˜ ๊ฐ’์„ ๋ฆฌ์ŠคํŠธ๋กœ ์–ป์Šต๋‹ˆ๋‹ค +9. _items()_ ๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•ด ํŠœํ”Œ์˜ ๋ฆฌ์ŠคํŠธ๋กœ ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค +10. ๋”•์…”๋„ˆ๋ฆฌ์˜ ์•„์ดํ…œ์ค‘ ํ•˜๋‚˜๋ฅผ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค +11. ๋”•์…”๋„ˆ๋ฆฌ ์ค‘ ํ•˜๋‚˜๋ฅผ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค + +๐ŸŽ‰ CONGRATULATIONS ! ๐ŸŽ‰ + +[<< Day 7 ](../07_Day_Sets/07_sets.md) | [Day 9 >>](../09_Day_Conditionals/09_conditionals.md)