Browse Source

๐ŸŒ Add Korean translation for `docs/ko/docs/python-types.md` (#2267)

pull/11011/head
JRIM 1 year ago
committed by GitHub
parent
commit
2a8f8d1ac0
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 315
      docs/ko/docs/python-types.md

315
docs/ko/docs/python-types.md

@ -0,0 +1,315 @@
# ํŒŒ์ด์ฌ ํƒ€์ž… ์†Œ๊ฐœ
ํŒŒ์ด์ฌ์€ ์„ ํƒ์ ์œผ๋กœ "ํƒ€์ž… ํžŒํŠธ(type hints)"๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
์ด๋Ÿฌํ•œ **ํƒ€์ž… ํžŒํŠธ**๋“ค์€ ๋ณ€์ˆ˜์˜ <abbr title="์˜ˆ๋ฅผ ๋“ค๋ฉด: str, int, float, bool">ํƒ€์ž…</abbr>์„ ์„ ์–ธํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ํŠน์ˆ˜ํ•œ ๊ตฌ๋ฌธ์ž…๋‹ˆ๋‹ค.
๋ณ€์ˆ˜์˜ ํƒ€์ž…์„ ์ง€์ •ํ•˜๋ฉด ์—๋””ํ„ฐ์™€ ํˆด์ด ๋” ๋งŽ์€ ๋„์›€์„ ์ค„ ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
์ด ๋ฌธ์„œ๋Š” ํŒŒ์ด์ฌ ํƒ€์ž… ํžŒํŠธ์— ๋Œ€ํ•œ **๋น ๋ฅธ ์ž์Šต์„œ / ๋‚ด์šฉํ™˜๊ธฐ** ์ˆ˜์ค€์˜ ๋ฌธ์„œ์ž…๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ๋Š” **FastAPI**๋ฅผ ์“ฐ๊ธฐ ์œ„ํ•œ ์ตœ์†Œํ•œ์˜ ๋‚ด์šฉ๋งŒ์„ ๋‹ค๋ฃน๋‹ˆ๋‹ค.
**FastAPI**๋Š” ํƒ€์ž… ํžŒํŠธ์— ๊ธฐ๋ฐ˜์„ ๋‘๊ณ  ์žˆ์œผ๋ฉฐ, ์ด๋Š” ๋งŽ์€ ์žฅ์ ๊ณผ ์ด์ต์ด ์žˆ์Šต๋‹ˆ๋‹ค.
๋น„๋ก **FastAPI**๋ฅผ ์“ฐ์ง€ ์•Š๋Š”๋‹ค๊ณ  ํ•˜๋”๋ผ๋„, ์กฐ๊ธˆ์ด๋ผ๋„ ์•Œ์•„๋‘๋ฉด ๋„์›€์ด ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.
!!! note "์ฐธ๊ณ "
ํŒŒ์ด์ฌ์— ๋Šฅ์ˆ™ํ•˜์…”์„œ ํƒ€์ž… ํžŒํŠธ์— ๋Œ€ํ•ด ๋ชจ๋‘ ์•„์‹ ๋‹ค๋ฉด, ๋‹ค์Œ ์ฑ•ํ„ฐ๋กœ ๊ฑด๋„ˆ๋›ฐ์„ธ์š”.
## ๋™๊ธฐ ๋ถ€์—ฌ
๊ฐ„๋‹จํ•œ ์˜ˆ์ œ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด๋ด…์‹œ๋‹ค:
```Python
{!../../../docs_src/python_types/tutorial001.py!}
```
์ด ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰ํ•œ ๊ฒฐ๊ณผ๊ฐ’:
```
John Doe
```
ํ•จ์ˆ˜๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค:
* `first_name`๊ณผ `last_name`๋ฅผ ๋ฐ›์Šต๋‹ˆ๋‹ค.
* `title()`๋กœ ๊ฐ ์ฒซ ๋ฌธ์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜์‹œํ‚ต๋‹ˆ๋‹ค.
* ๋‘ ๋‹จ์–ด๋ฅผ ์ค‘๊ฐ„์— ๊ณต๋ฐฑ์„ ๋‘๊ณ  <abbr title="๋‘ ๊ฐœ๋ฅผ ํ•˜๋‚˜๋กœ ์ฐจ๋ก€์ฐจ๋ก€ ์ด์–ด์ง€๊ฒŒ ํ•˜๋‹ค">์—ฐ๊ฒฐ</abbr>ํ•ฉ๋‹ˆ๋‹ค.
```Python hl_lines="2"
{!../../../docs_src/python_types/tutorial001.py!}
```
### ์ฝ”๋“œ ์ˆ˜์ •
์ด๊ฑด ๋งค์šฐ ๊ฐ„๋‹จํ•œ ํ”„๋กœ๊ทธ๋žจ์ž…๋‹ˆ๋‹ค.
๊ทธ๋Ÿฐ๋ฐ ์ฒ˜์Œ๋ถ€ํ„ฐ ์ž‘์„ฑํ•œ๋‹ค๊ณ  ์ƒ๊ฐ์„ ํ•ด๋ด…์‹œ๋‹ค.
์—ฌ๋Ÿฌ๋ถ„์€ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ค€๋น„ํ–ˆ๊ณ , ํ•จ์ˆ˜๋ฅผ ์ •์˜ํ•˜๊ธฐ ์‹œ์ž‘ํ–ˆ์„ ๊ฒ๋‹ˆ๋‹ค.
์ด๋•Œ "์ฒซ ๊ธ€์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ๋ฐ”๊พธ๋Š” ํ•จ์ˆ˜"๋ฅผ ํ˜ธ์ถœํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
`upper`์˜€๋‚˜? ์•„๋‹ˆ๋ฉด `uppercase`? `first_uppercase`? `capitalize`?
๊ทธ๋•Œ ๊ฐœ๋ฐœ์ž๋“ค์˜ ์˜ค๋žœ ์นœ๊ตฌ, ์—๋””ํ„ฐ ์ž๋™์™„์„ฑ์„ ์‹œ๋„ํ•ด๋ด…๋‹ˆ๋‹ค.
๋‹น์‹ ์€ `first_name`๋ฅผ ์ž…๋ ฅํ•œ ๋’ค ์ (`.`)์„ ์ž…๋ ฅํ•˜๊ณ  ์ž๋™์™„์„ฑ์„ ์ผœ๊ธฐ ์œ„ํ•ด์„œ `Ctrl+Space`๋ฅผ ๋ˆŒ๋ €์Šต๋‹ˆ๋‹ค.
ํ•˜์ง€๋งŒ ์Šฌํ”„๊ฒŒ๋„ ์•„๋ฌด๋Ÿฐ ๋„์›€์ด ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค:
<img src="/img/python-types/image01.png">
### ํƒ€์ž… ์ถ”๊ฐ€ํ•˜๊ธฐ
์ด์ „ ๋ฒ„์ „์—์„œ ํ•œ ์ค„๋งŒ ์ˆ˜์ •ํ•ด๋ด…์‹œ๋‹ค.
์ €ํฌ๋Š” ์ด ํ•จ์ˆ˜์˜ ๋งค๊ฐœ๋ณ€์ˆ˜ ๋ถ€๋ถ„:
```Python
first_name, last_name
```
์„ ์•„๋ž˜์™€ ๊ฐ™์ด ๋ฐ”๊ฟ€ ๊ฒ๋‹ˆ๋‹ค:
```Python
first_name: str, last_name: str
```
์ด๊ฒŒ ๋‹ค์ž…๋‹ˆ๋‹ค.
์ด๊ฒŒ "ํƒ€์ž… ํžŒํŠธ"์ž…๋‹ˆ๋‹ค:
```Python hl_lines="1"
{!../../../docs_src/python_types/tutorial002.py!}
```
ํƒ€์ž…ํžŒํŠธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ธฐ๋ณธ ๊ฐ’์„ ์„ ์–ธํ•˜๋Š” ๊ฒƒ๊ณผ๋Š” ๋‹ค๋ฆ…๋‹ˆ๋‹ค:
```Python
first_name="john", last_name="doe"
```
์ด๋Š” ๋‹ค๋ฅธ ๊ฒƒ์ž…๋‹ˆ๋‹ค.
๋“ฑํ˜ธ(`=`) ๋Œ€์‹  ์ฝœ๋ก (`:`)์„ ์“ฐ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
์ผ๋ฐ˜์ ์œผ๋กœ ํƒ€์ž…ํžŒํŠธ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค๊ณ  ํ•ด์„œ ํŠน๋ณ„ํ•˜๊ฒŒ ์–ด๋–ค ์ผ์ด ์ผ์–ด๋‚˜์ง€๋„ ์•Š์Šต๋‹ˆ๋‹ค.
๊ทธ๋ ‡์ง€๋งŒ ์ด์ œ, ๋‹ค์‹œ ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“œ๋Š” ๋„์ค‘์ด๋ผ๊ณ  ์ƒ๊ฐํ•ด๋ด…์‹œ๋‹ค. ๋‹ค๋งŒ ์ด๋ฒˆ์—” ํƒ€์ž… ํžŒํŠธ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
๊ฐ™์€ ์ƒํ™ฉ์—์„œ `Ctrl+Space`๋กœ ์ž๋™์™„์„ฑ์„ ์ž‘๋™์‹œํ‚ค๋ฉด,
<img src="/img/python-types/image02.png">
์•„๋ž˜์™€ ๊ฐ™์ด "๊ทธ๋ ‡์ง€!"ํ•˜๋Š” ์˜ต์…˜์ด ๋‚˜์˜ฌ๋•Œ๊นŒ์ง€ ์Šคํฌ๋กค์„ ๋‚ด๋ ค์„œ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
<img src="/img/python-types/image03.png">
## ๋” ํฐ ๋™๊ธฐ๋ถ€์—ฌ
์•„๋ž˜ ํ•จ์ˆ˜๋ฅผ ๋ณด๋ฉด, ์ด๋ฏธ ํƒ€์ž… ํžŒํŠธ๊ฐ€ ์ ์šฉ๋˜์–ด ์žˆ๋Š” ๊ฑธ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
```Python hl_lines="1"
{!../../../docs_src/python_types/tutorial003.py!}
```
ํŽธ์ง‘๊ธฐ๊ฐ€ ๋ณ€์ˆ˜์˜ ํƒ€์ž…์„ ์•Œ๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, ์ž๋™์™„์„ฑ ๋ฟ ์•„๋‹ˆ๋ผ ์—๋Ÿฌ๋„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
<img src="/img/python-types/image04.png">
์ด์ œ ๊ณ ์ณ์•ผํ•˜๋Š” ๊ฑธ ์•Œ๊ธฐ ๋•Œ๋ฌธ์—, `age`๋ฅผ `str(age)`๊ณผ ๊ฐ™์ด ๋ฌธ์ž์—ด๋กœ ๋ฐ”๊พธ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค:
```Python hl_lines="2"
{!../../../docs_src/python_types/tutorial004.py!}
```
## ํƒ€์ž… ์„ ์–ธ
๋ฐฉ๊ธˆ ํ•จ์ˆ˜์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ์จ ํƒ€์ž… ํžŒํŠธ๋ฅผ ์„ ์–ธํ•˜๋Š” ์ฃผ์š” ์žฅ์†Œ๋ฅผ ๋ณด์•˜์Šต๋‹ˆ๋‹ค.
์ด ์œ„์น˜๋Š” ์—ฌ๋Ÿฌ๋ถ„์ด **FastAPI**์™€ ํ•จ๊ป˜ ์ด๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ฃผ์š” ์žฅ์†Œ์ž…๋‹ˆ๋‹ค.
### Simple ํƒ€์ž…
`str`๋ฟ ์•„๋‹ˆ๋ผ ๋ชจ๋“  ํŒŒ์ด์ฌ ํ‘œ์ค€ ํƒ€์ž…์„ ์„ ์–ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค๋ฉด:
* `int`
* `float`
* `bool`
* `bytes`
```Python hl_lines="1"
{!../../../docs_src/python_types/tutorial005.py!}
```
### ํƒ€์ž… ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ํ™œ์šฉํ•œ Generic(์ œ๋„ค๋ฆญ) ํƒ€์ž…
`dict`, `list`, `set`, `tuple`๊ณผ ๊ฐ™์€ ๊ฐ’์„ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ๊ฐ€ ์žˆ๊ณ , ๋‚ด๋ถ€์˜ ๊ฐ’์€ ๊ฐ์ž์˜ ํƒ€์ž…์„ ๊ฐ€์งˆ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
ํƒ€์ž…๊ณผ ๋‚ด๋ถ€ ํƒ€์ž…์„ ์„ ์–ธํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ํŒŒ์ด์ฌ ํ‘œ์ค€ ๋ชจ๋“ˆ์ธ `typing`์„ ์ด์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
๊ตฌ์ฒด์ ์œผ๋กœ๋Š” ์•„๋ž˜ ํƒ€์ž… ํžŒํŠธ๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
#### `List`
์˜ˆ๋ฅผ ๋“ค๋ฉด, `str`์˜ `list`์ธ ๋ณ€์ˆ˜๋ฅผ ์ •์˜ํ•ด๋ด…์‹œ๋‹ค.
`typing`์—์„œ `List`(๋Œ€๋ฌธ์ž `L`)๋ฅผ import ํ•ฉ๋‹ˆ๋‹ค.
```Python hl_lines="1"
{!../../../docs_src/python_types/tutorial006.py!}
```
์ฝœ๋ก (`:`) ๋ฌธ๋ฒ•์„ ์ด์šฉํ•˜์—ฌ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค.
ํƒ€์ž…์œผ๋กœ๋Š” `List`๋ฅผ ๋„ฃ์–ด์ค๋‹ˆ๋‹ค.
์ด๋•Œ ๋ฐฐ์—ด์€ ๋‚ด๋ถ€ ํƒ€์ž…์„ ํฌํ•จํ•˜๋Š” ํƒ€์ž…์ด๊ธฐ ๋•Œ๋ฌธ์— ๋Œ€๊ด„ํ˜ธ ์•ˆ์— ๋„ฃ์–ด์ค๋‹ˆ๋‹ค.
```Python hl_lines="4"
{!../../../docs_src/python_types/tutorial006.py!}
```
!!! tip "ํŒ"
๋Œ€๊ด„ํ˜ธ ์•ˆ์˜ ๋‚ด๋ถ€ ํƒ€์ž…์€ "ํƒ€์ž… ๋งค๊ฐœ๋ณ€์ˆ˜(type paramters)"๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
์ด๋ฒˆ ์˜ˆ์ œ์—์„œ๋Š” `str`์ด `List`์— ๋“ค์–ด๊ฐ„ ํƒ€์ž… ๋งค๊ฐœ๋ณ€์ˆ˜ ์ž…๋‹ˆ๋‹ค.
์ด๋Š” "`items`์€ `list`์ธ๋ฐ, ๋ฐฐ์—ด์— ๋“ค์–ด์žˆ๋Š” ์•„์ดํ…œ ๊ฐ๊ฐ์€ `str`์ด๋‹ค"๋ผ๋Š” ๋œป์ž…๋‹ˆ๋‹ค.
์ด๋ ‡๊ฒŒ ํ•จ์œผ๋กœ์จ, ์—๋””ํ„ฐ๋Š” ๋ฐฐ์—ด์— ๋“ค์–ด์žˆ๋Š” ์•„์ดํ…œ์„ ์ฒ˜๋ฆฌํ• ๋•Œ๋„ ๋„์›€์„ ์ค„ ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค:
<img src="/img/python-types/image05.png">
ํƒ€์ž…์ด ์—†์œผ๋ฉด ์ด๊ฑด ๊ฑฐ์˜ ๋ถˆ๊ฐ€๋Šฅ์ด๋‚˜ ๋‹ค๋ฆ„ ์—†์Šต๋‹ˆ๋‹ค.
๋ณ€์ˆ˜ `item`์€ `items`์˜ ๊ฐœ๋ณ„ ์š”์†Œ๋ผ๋Š” ์‚ฌ์‹ค์„ ์•Œ์•„๋‘์„ธ์š”.
๊ทธ๋ฆฌ๊ณ  ์—๋””ํ„ฐ๋Š” ๊ณ„์† `str`๋ผ๋Š” ์‚ฌ์‹ค์„ ์•Œ๊ณ  ๋„์™€์ค๋‹ˆ๋‹ค.
#### `Tuple`๊ณผ `Set`
`tuple`๊ณผ `set`๋„ ๋™์ผํ•˜๊ฒŒ ์„ ์–ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
```Python hl_lines="1 4"
{!../../../docs_src/python_types/tutorial007.py!}
```
์ด ๋œป์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค:
* ๋ณ€์ˆ˜ `items_t`๋Š”, ์ฐจ๋ก€๋Œ€๋กœ `int`, `int`, `str`์ธ `tuple`์ด๋‹ค.
* ๋ณ€์ˆ˜ `items_s`๋Š”, ๊ฐ ์•„์ดํ…œ์ด `bytes`์ธ `set`์ด๋‹ค.
#### `Dict`
`dict`๋ฅผ ์„ ์–ธํ•˜๋ ค๋ฉด ์ปด๋งˆ๋กœ ๊ตฌ๋ถ„๋œ 2๊ฐœ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
์ฒซ ๋ฒˆ์งธ ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” `dict`์˜ ํ‚ค(key)์ด๊ณ ,
๋‘ ๋ฒˆ์งธ ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” `dict`์˜ ๊ฐ’(value)์ž…๋‹ˆ๋‹ค.
```Python hl_lines="1 4"
{!../../../docs_src/python_types/tutorial008.py!}
```
์ด ๋œป์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค:
* ๋ณ€์ˆ˜ `prices`๋Š” `dict`์ด๋‹ค:
* `dict`์˜ ํ‚ค(key)๋Š” `str`ํƒ€์ž…์ด๋‹ค. (๊ฐ ์•„์ดํ…œ์˜ ์ด๋ฆ„(name))
* `dict`์˜ ๊ฐ’(value)๋Š” `float`ํƒ€์ž…์ด๋‹ค. (๊ฐ ์•„์ดํ…œ์˜ ๊ฐ€๊ฒฉ(price))
#### `Optional`
`str`๊ณผ ๊ฐ™์ด ํƒ€์ž…์„ ์„ ์–ธํ•  ๋•Œ `Optional`์„ ์“ธ ์ˆ˜๋„ ์žˆ๋Š”๋ฐ, "์„ ํƒ์ (Optional)"์ด๊ธฐ๋•Œ๋ฌธ์— `None`๋„ ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
```Python hl_lines="1 4"
{!../../../docs_src/python_types/tutorial009.py!}
```
`Optional[str]`์„ `str` ๋Œ€์‹  ์“ฐ๊ฒŒ ๋˜๋ฉด, ํŠน์ • ๊ฐ’์ด ์‹ค์ œ๋กœ๋Š” `None`์ด ๋  ์ˆ˜๋„ ์žˆ๋Š”๋ฐ ํ•ญ์ƒ `str`์ด๋ผ๊ณ  ๊ฐ€์ •ํ•˜๋Š” ์ƒํ™ฉ์—์„œ ์—๋””ํ„ฐ๊ฐ€ ์—๋Ÿฌ๋ฅผ ์ฐพ๊ฒŒ ๋„์™€์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
#### Generic(์ œ๋„ค๋ฆญ) ํƒ€์ž…
์ด ํƒ€์ž…์€ ๋Œ€๊ด„ํ˜ธ ์•ˆ์— ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๊ฐ€์ง€๋ฉฐ, ์ข…๋ฅ˜๋Š”:
* `List`
* `Tuple`
* `Set`
* `Dict`
* `Optional`
* ...๋“ฑ๋“ฑ
์œ„์™€ ๊ฐ™์€ ํƒ€์ž…์€ **Generic(์ œ๋„ค๋ฆญ) ํƒ€์ž…** ํ˜น์€ **Generics(์ œ๋„ค๋ฆญ์Šค)**๋ผ๊ณ  ๋ถˆ๋ฆฝ๋‹ˆ๋‹ค.
### ํƒ€์ž…์œผ๋กœ์„œ์˜ ํด๋ž˜์Šค
๋ณ€์ˆ˜์˜ ํƒ€์ž…์œผ๋กœ ํด๋ž˜์Šค๋ฅผ ์„ ์–ธํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
์ด๋ฆ„(name)์„ ๊ฐ€์ง„ `Person` ํด๋ž˜์Šค๊ฐ€ ์žˆ๋‹ค๊ณ  ํ•ด๋ด…์‹œ๋‹ค.
```Python hl_lines="1-3"
{!../../../docs_src/python_types/tutorial010.py!}
```
๊ทธ๋ ‡๊ฒŒ ํ•˜๋ฉด ๋ณ€์ˆ˜๋ฅผ `Person`์ด๋ผ๊ณ  ์„ ์–ธํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
```Python hl_lines="6"
{!../../../docs_src/python_types/tutorial010.py!}
```
๊ทธ๋ฆฌ๊ณ  ์—ญ์‹œ๋‚˜ ๋ชจ๋“  ์—๋””ํ„ฐ ๋„์›€์„ ๋ฐ›๊ฒŒ ๋˜๊ฒ ์ฃ .
<img src="/img/python-types/image06.png">
## Pydantic ๋ชจ๋ธ
<a href="https://pydantic-docs.helpmanual.io/" class="external-link" target="_blank">Pydantic</a>์€ ๋ฐ์ดํ„ฐ ๊ฒ€์ฆ(Validation)์„ ์œ„ํ•œ ํŒŒ์ด์ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค.
๋‹น์‹ ์€ ์†์„ฑ๋“ค์„ ํฌํ•จํ•œ ํด๋ž˜์Šค ํ˜•ํƒœ๋กœ "๋ชจ์–‘(shape)"์„ ์„ ์–ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  ๊ฐ ์†์„ฑ์€ ํƒ€์ž…์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
์ด ํด๋ž˜์Šค๋ฅผ ํ™œ์šฉํ•˜์—ฌ์„œ ๊ฐ’์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค๊ฒŒ ๋˜๋ฉด, ํ•„์š”ํ•œ ๊ฒฝ์šฐ์—๋Š” ์ ๋‹นํ•œ ํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜๊นŒ์ง€ ์‹œํ‚ค๊ธฐ๋„ ํ•˜์—ฌ ๋ฐ์ดํ„ฐ๊ฐ€ ํฌํ•จ๋œ ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  ๊ฒฐ๊ณผ ๊ฐ์ฒด์— ๋Œ€ํ•ด์„œ๋Š” ์—๋””ํ„ฐ์˜ ๋„์›€์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
Pydantic ๊ณต์‹ ๋ฌธ์„œ ์˜ˆ์‹œ:
```Python
{!../../../docs_src/python_types/tutorial011.py!}
```
!!! info "์ •๋ณด"
Pydantic<์— ๋Œ€ํ•ด ๋” ๋ฐฐ์šฐ๊ณ  ์‹ถ๋‹ค๋ฉด <a href="https://pydantic-docs.helpmanual.io/" class="external-link" target="_blank">๊ณต์‹ ๋ฌธ์„œ</a>๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”.</a>
**FastAPI**๋Š” ๋ชจ๋‘ Pydantic์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
์ด ๋ชจ๋“  ๊ฒƒ์ด ์‹ค์ œ๋กœ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉ๋˜๋Š”์ง€์— ๋Œ€ํ•ด์„œ๋Š” [์ž์Šต์„œ - ์‚ฌ์šฉ์ž ์•ˆ๋‚ด์„œ](tutorial/index.md){.internal-link target=_blank} ์—์„œ ๋” ๋งŽ์ด ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
## **FastAPI**์—์„œ์˜ ํƒ€์ž… ํžŒํŠธ
**FastAPI**๋Š” ์—ฌ๋Ÿฌ ๋ถ€๋ถ„์—์„œ ํƒ€์ž… ํžŒํŠธ์˜ ์žฅ์ ์„ ์ทจํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
**FastAPI**์—์„œ ํƒ€์ž… ํžŒํŠธ์™€ ํ•จ๊ป˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๋ฉด ์žฅ์ ์€:
* **์—๋””ํ„ฐ ๋„์›€**.
* **ํƒ€์ž… ํ™•์ธ**.
...๊ทธ๋ฆฌ๊ณ  **FastAPI**๋Š” ๊ฐ™์€ ์ •์˜๋ฅผ ์•„๋ž˜์—๋„ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค:
* **์š”๊ตฌ์‚ฌํ•ญ ์ •์˜**: ์š”์ฒญ ๊ฒฝ๋กœ ๋งค๊ฐœ๋ณ€์ˆ˜, ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜, ํ—ค๋”, ๋ฐ”๋””, ์˜์กด์„ฑ ๋“ฑ.
* **๋ฐ์ดํ„ฐ ๋ณ€ํ™˜**: ์š”์ฒญ์—์„œ ์š”๊ตฌํ•œ ํƒ€์ž…์œผ๋กœ.
* **๋ฐ์ดํ„ฐ ๊ฒ€์ฆ**: ๊ฐ ์š”์ฒญ๋งˆ๋‹ค:
* ๋ฐ์ดํ„ฐ๊ฐ€ ์œ ํšจํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ์—๋Š” **์ž๋™์œผ๋กœ ์—๋Ÿฌ**๋ฅผ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.
* OpenAPI๋ฅผ ํ™œ์šฉํ•œ **API ๋ฌธ์„œํ™”**:
* ์ž๋™์œผ๋กœ ์ƒํ˜ธ์ž‘์šฉํ•˜๋Š” ์œ ์ € ์ธํ„ฐํŽ˜์ด์Šค์— ์“ฐ์ด๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
์œ„ ๋‚ด์šฉ์ด ๋‹ค์†Œ ์ถ”์ƒ์ ์ผ ์ˆ˜๋„ ์žˆ์ง€๋งŒ, ๊ฑฑ์ •๋งˆ์„ธ์š”. [์ž์Šต์„œ - ์‚ฌ์šฉ์ž ์•ˆ๋‚ด์„œ](tutorial/index.md){.internal-link target=_blank}์—์„œ ์ „๋ถ€ ํ™•์ธ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ฑด, ํ‘œ์ค€ ํŒŒ์ด์ฌ ํƒ€์ž…์„ ํ•œ ๊ณณ์—์„œ(ํด๋ž˜์Šค๋ฅผ ๋”ํ•˜๊ฑฐ๋‚˜, ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ ์‚ฌ์šฉํ•˜๋Š” ๋Œ€์‹ ) ์‚ฌ์šฉํ•จ์œผ๋กœ์จ **FastAPI**๊ฐ€ ๋‹น์‹ ์„ ์œ„ํ•ด ๋งŽ์€ ์ผ์„ ํ•ด์ค€๋‹ค๋Š” ์‚ฌ์‹ค์ด์ฃ .
!!! info "์ •๋ณด"
๋งŒ์•ฝ ๋ชจ๋“  ์ž์Šต์„œ๋ฅผ ๋‹ค ๋ณด์•˜์Œ์—๋„ ํƒ€์ž…์— ๋Œ€ํ•ด์„œ ๋” ๋ณด๊ณ ์ž ๋ฐฉ๋ฌธํ•œ ๊ฒฝ์šฐ์—๋Š” <a href="https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html" class="external-link" target="_blank">`mypy`์—์„œ ์ œ๊ณตํ•˜๋Š” "cheat sheet"</a>์ด ์ข‹์€ ์ž๋ฃŒ๊ฐ€ ๋  ๊ฒ๋‹ˆ๋‹ค.
Loadingโ€ฆ
Cancel
Save