Guidelines

데이터λ₯Ό λ‹΄λŠ” μƒμž, λ³€μˆ˜

ν”„λ‘œκ·Έλž˜λ°μ—μ„œ λ³€μˆ˜(Variable)λŠ” 데이터λ₯Ό λ‹΄λŠ” μƒμžλ₯Ό λœ»ν•©λ‹ˆλ‹€.

데이터에 이름을 λΆ€μ—¬ν•΄ 값을 μ €μž₯ν•˜κ³ , ν•„μš”μ— 따라 μ €μž₯된 값을 μˆ˜μ •ν•˜κ±°λ‚˜ μ°Έμ‘°ν•  수 μžˆμŠ΅λ‹ˆλ‹€.


λ³€μˆ˜μ˜ 의미

λ³€μˆ˜λŠ” 데이터λ₯Ό μ €μž₯ν•˜κΈ° μœ„ν•œ λ©”λͺ¨λ¦¬(데이터와 λͺ…λ Ήμ–΄λ₯Ό μž„μ‹œ μ €μž₯ν•˜λŠ” κ³³)의 μœ„μΉ˜λ₯Ό κ°€λ¦¬ν‚€λŠ” μ΄λ¦„μž…λ‹ˆλ‹€.

νŒŒμ΄μ¬μ—μ„œλŠ” λ³€μˆ˜λ₯Ό μ„ μ–Έν•  λ•Œ λ³„λ„μ˜ ν‚€μ›Œλ“œ(예: var, let)κ°€ ν•„μš”ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. κ°„λ‹¨νžˆ λ³€μˆ˜λͺ…을 적고, λ“±ν˜Έ ν‘œμ‹œ(=)둜 값을 ν• λ‹Ήν•©λ‹ˆλ‹€.

λ³€μˆ˜ μ„ μ–Έκ³Ό ν• λ‹Ή
my_variable = 10 # my_variable λ³€μˆ˜μ— 10 ν• λ‹Ή name = "μ½”λ“œν”„λ Œμ¦ˆ" # name λ³€μˆ˜μ— "μ½”λ“œν”„λ Œμ¦ˆ" ν• λ‹Ή

λ³€μˆ˜ μ„ μ–Έκ³Ό μ΄ˆκΈ°ν™”

λ³€μˆ˜λ₯Ό μ„ μ–Έ(Declaare)ν•œλ‹€λŠ” 것은 λ³€μˆ˜λ₯Ό μ‚¬μš©ν•  μ€€λΉ„λ₯Ό ν•œλ‹€λŠ” μ˜λ―Έμž…λ‹ˆλ‹€.

λ³€μˆ˜λ₯Ό μ„ μ–Έν•  λ•Œ λ³€μˆ˜μ— 값을 ν• λ‹Ήν•˜λŠ” 것을 μ΄ˆκΈ°ν™”(Initialization)라고 ν•©λ‹ˆλ‹€.

λ³€μˆ˜ μ„ μ–Έκ³Ό μ΄ˆκΈ°ν™”
# my_variable λ³€μˆ˜ μ„ μ–Έ my_variable = 10 # μ΄ˆκΈ°ν™”: 10 ν• λ‹Ή

νŒŒμ΄μ¬μ€ λ³€μˆ˜λ₯Ό μ„ μ–Έλ§Œν•˜κ³  μ΄ˆκΈ°ν™”ν•˜μ§€ μ•ŠμœΌλ©΄ NameError 였λ₯˜κ°€ λ°œμƒν•©λ‹ˆλ‹€.

λ³€μˆ˜ μ„ μ–Έλ§Œν•œ 경우
# μ΄ˆκΈ°ν™” 없이 λ³€μˆ˜ μ„ μ–Έ μ‹œλ„ x # NameError: name 'x' is not defined

λ”°λΌμ„œ νŒŒμ΄μ¬μ—μ„œ λ³€μˆ˜λ₯Ό μ„ μ–Έν•  λ•ŒλŠ” λ“±ν˜Έ(=)λ₯Ό μ‚¬μš©ν•΄ λ°˜λ“œμ‹œ μ΄ˆκΈ°ν™”ν•΄μ•Ό ν•©λ‹ˆλ‹€.


파이썬 λ³€μˆ˜μ˜ νŠΉμ§•

  • 동적 μžλ£Œν˜•: λ³€μˆ˜μ˜ μžλ£Œν˜•(Type, ν…μŠ€νŠΈ, μˆ«μžμ™€ 같은 자료의 ν˜•νƒœ)이 ν”„λ‘œκ·Έλž¨ μ‹€ν–‰ 쀑에 κ²°μ •λ˜λ©°, μ½”λ“œ μž‘μ„± μ‹œ λ³€μˆ˜ νƒ€μž…μ„ 미리 μ„ μ–Έν•  ν•„μš” μ—†μŠ΅λ‹ˆλ‹€.

  • μž¬ν• λ‹Ή κ°€λŠ₯: λ³€μˆ˜μ— μ €μž₯된 값을 λ³€κ²½ν•˜κ±°λ‚˜ λ‹€λ₯Έ νƒ€μž…μ˜ κ°’μœΌλ‘œ μž¬ν• λ‹Ήν•  수 μžˆμŠ΅λ‹ˆλ‹€.

동적 μžλ£Œν˜•κ³Ό μž¬ν• λ‹Ή
number = 5 # μ •μˆ˜(숫자) ν• λ‹Ή number = "five" # λ¬Έμžμ—΄(ν…μŠ€νŠΈ)둜 μž¬ν• λ‹Ή

μ½”λ”© μ‹€μŠ΅

λ³€μˆ˜ greeting에 λ¬Έμžμ—΄ "hello"λ₯Ό ν• λ‹Ήν•΄ λ³΄μ„Έμš”.

Mission
0 / 1

νŒŒμ΄μ¬μ—μ„œ λ³€μˆ˜λ₯Ό μ„ μ–Έν•  λ•Œ varλ‚˜ let ν‚€μ›Œλ“œλ₯Ό λ°˜λ“œμ‹œ μ‚¬μš©ν•΄μ•Ό ν•œλ‹€.

O
X

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result