2์ฐจ์_์๋ฃํ_๊ณผ์ .docx
2.41MB
2์ฐจ์_์๋ฃํ_๊ฐ์์.pdf
1.79MB
*๋ชจ๋ ์ถ์ฒ๋ ๋์ "๋ฐ์ดํฐ ๊ณผํ์ ์ํ ํ์ด์ฌ ํ๋ก๊ทธ๋๋ฐ"์
๋๋ค
# 1. ๋ณ์์ ์ดํด
๋ณ์์ ๊ฐ
- ๋ณ์?
- โname = โKim Kyureeโโ
- name์ด๋ผ๋ ๊ณต๊ฐ์ Kim Kyuree๋ผ๋ ๊ธ์๋ฅผ ๋ฃ์ด๋ผ!
- name์ด๋ผ๋ ๋ณ์์ Kim Kyuree๋ผ๋ ๊ฐ์ ๋ฃ์ด๋ผ
- โname = โKim Kyureeโโ
name = 'Kim Kyuree'
print(name) #Kim Kyuree
name = 'Kim Kyuree'
print(name) #Kim Kyuree
- ๋ณ์์ ๊ฐ ํ ๋นํ๊ธฐ
- โ=โ ๊ธฐํธ ํ์ฉ
- ๊ฐ์ ๋ณ์์ ๋ฃ์ด๋ผ
- ๊ธฐ๋ณธ ๋ฌธ๋ฒ
- [๋ณ์๋ช = ๊ฐ]
- โ=โ ๊ธฐํธ ํ์ฉ

-
- ๋ณ์ a์ 3, ๋ณ์ b์ 5๋ฅผ ํ ๋นํ๋ ๊ฒ์ ๋์ผ
- ๋ฐ์ดํ(โ โ) ์ฌ์ฉ ์ฌ๋ถ์ ์ฐจ์ด
- ์์ ) print(a+b) vs. print( โa + bโ)
a = 3
b = 5
print(a + b) #8
a = 3
b = 5
print('a + b') #a + b
- ๋ณ์ a์ 3, ๋ณ์ b์ 5๋ฅผ ํ ๋นํ๋ ๊ฒ์ ๋์ผ
- ๋ฐ์ดํ(โ โ) ์ฌ์ฉ ์ฌ๋ถ์ ์ฐจ์ด

โ ๋ฐ์ดํ ์์ ๊ฐ์ ํ๋์ ๊ฐ์ผ๋ก ๊ฐ์ฃผ
๐ญ ํ์ด์ฌ์์๋ ๋ณ์์ ๊ฐ์ ํตํด ๋ชจ๋ ํ๋ก๊ทธ๋๋ฐ ์์!
๋ณ์๋ช ์ ์ธ
- ๊ท์น
- ์ํ๋ฒณ, ์ซ์, ๋ฐ์ค(_)๋ก ๊ตฌ์ฑ๊ฐ๋ฅ (* ์ซ์๋ก ์์ํ ์ ์๋ค)
- Ex. name, age, num1, total_score ,
1num, 5_stars
- Ex. name, age, num1, total_score ,
- ๋ณ์๋ช
์ ์๋ฏธ ์๋ ๋จ์ด๋ก ์ ์
- Ex. student_name, score, id ..
- ๋ณ์๋ช
๋์๋ฌธ์ ๊ตฌ๋ถ
- Ex, option๊ณผ Option์ **๋ค๋ฅธ **๋ณ์
- ํน๋ณํ ์๋ฏธ๊ฐ ์๋ ์์ฝ์ด๋ ์ฌ์ฉ๋ถ๊ฐ
- Ex. for, if, else, print, input, as, type..
- ํจ์๋ช , ๋ช ๋ น ํค์๋
- ์ํ๋ฒณ, ์ซ์, ๋ฐ์ค(_)๋ก ๊ตฌ์ฑ๊ฐ๋ฅ (* ์ซ์๋ก ์์ํ ์ ์๋ค)
- ์ ์ํ ์
- ์๋ฏธ์๋ ์ด๋ฆ์ผ๋ก ์ ์ธ for ํ์ธ๊ณผ ์์ฌ์ํต
- ex. a , b ,c โฆ โ ๋ณ์์ ๊ฐ ์๋ฏธ ์์์ฑ๊ธฐ ์ด๋ ต..
- ๋ณ์ ๊ด๋ จ ์๋ฌ
- NameError: name โxxโ is not defined
- ๋ณ์๋ช ์ ์คํ ์๊ฑฐ๋, ์ ์ธํ์ง ์์๊ฑฐ๋ ๋ฑ..
- ์๋ฏธ์๋ ์ด๋ฆ์ผ๋ก ์ ์ธ for ํ์ธ๊ณผ ์์ฌ์ํต
#2. ์๋ฃํ๊ณผ ๊ธฐ๋ณธ ์ฐ์ฐ
๊ธฐ๋ณธ ์๋ฃํ
- ์ ์ํ(inter type): ์์ฐ์ ํฌํจ, ๊ฐ์ ์์ญ์ด ์ ์๋ก ํ์ ๋ ๊ฐ
- -1, 0, 1, 49 ..
- ex. data = 1
- ์ค์ํ(floating type): ์์์ ์ด ํฌํจ๋ ๊ฐ
- 10.2, 6.0, -0.3 ..
- 9 vs 9.0
- ๋ฌธ์ํ(string type): ๋ฌธ์๋ก ์ถ๋ ฅ๋๋ ๊ฐ, โ โ & โ โ ์์ ํฌํจ๋๋ ๊ฐ
- โappleโ, โabcโ ..
- print(โa+bโ) vs. print(a+b)
- ๋ถ๋ฆฐํ(boolean type): ๋
ผ๋ฆฌํ, ์ฐธ ํน์ ๊ฑฐ์ง, True False
- True, False

๊ฐ๋จํ ์ฐ์ฐ
- ์ฐ์ฐ์& ํผ์ฐ์ฐ์
- ์ฐ์ฐ์ : + - * %
- ํผ์ฐ์ฐ์ : ์ฐ์ฐ์์ ์ํด ๊ณ์ฐ๋๋ ์ซ์
- ex. 3+2 โ 3,2 ํผ์ฐ์ฐ์, + ์ฐ์ฐ์
- ์ํ์์์ ์ฐ์ฐ์ ์ญํ , ์ฐ์ฐ์์ ๋์ผ
- ์ฌ์น์ฐ์ฐ
- +, - โ ๋ง์
, ๋บ์
- , / โ ๊ณฑ์ , ๋๋์
- 25 + 37 # 62 50 - 19 # 31 50 * 3 # 150 30 / 5 # 6.0
- +, - โ ๋ง์
, ๋บ์
- ์ ๊ณฑ์น
- ์ฐ์ฐ์: **
- 3์ 5์น โ 3**5
- 3 * 3 * 3 * 3 * 3
- ์ฐ์ฐ์: **
- ๋๋์
์ ๋ชซ๊ณผ ๋๋จธ์ง
- ๋ชซ ๋ฐํ ์ฐ์ฐ์: //
- ex. 7//4 โ 1
- ๋๋จธ์ง ๋ฐํ ์ฐ์ฐ์: %
- ex. 7%4 โ 3
- ๊ดํธ ์ฌ์ฉ : (), ๊ดํธ ์ ์ฐ์ ๊ณ์ฐ
- ex. 2*(3+4) โ 14
- ๋ชซ ๋ฐํ ์ฐ์ฐ์: //
- ์ฆ๊ฐ ์ฐ์ฐ & ๊ฐ์ ์ฐ์ฐ
- ์ฆ๊ฐ ์ฐ์ฐ : [๋ณ์ += ๋ํ ๊ฐ]
- ex. a = a + 1 < = > a += 1
- ๊ฐ์ ์ฐ์ฐ: [๋ณ์ -= ๋บ ๊ฐ]
- ์ฆ๊ฐ ์ฐ์ฐ : [๋ณ์ += ๋ํ ๊ฐ]
- a = 1 a = a + 1 print(a) #2 a += 1 #a์ 1 ๋ํ๊ธฐ print(a) #3 a = a - 1 #2 a -= 1 #a์์ 1 ๋นผ๊ธฐ print(a) #1
- +) ์ฐ์ฐ์ ์ด์ฉ ์ฐ๊ฒฐ
- ์ซ์ + ์ซ์ โ ๋ํ๊ธฐ
- ๋ฌธ์ + ๋ฌธ์ โ ๋ ๋ฌธ์ ์ด์ด ์ฐ๊ฒฐ
- ๋ฌธ์ * ์ซ์ โ ๋ฌธ์๋ฅผ ์ซ์๋งํผ ๋ฐ๋ณต
- ์ด ๊ฒฝ์ฐ, * ์ ์ธ ๋ชจ๋ ์ค๋ฅ ๋ฐ์
#3. ์๋ฃํ ๋ณํ
์ ์ํ๊ณผ ์ค์ํ ๊ฐ์ ๋ณํ
- ํ๋ก๊ทธ๋๋ฐ, 4๊ฐ์ง ์๋ฃํ ์์ ๋กญ๊ฒ ๋ณํํ์ฌ ๋ค๋ฃจ๋ ๊ฒฝ์ฐ ๋ง์
- ์ธํฐ๋ท ๋ก๊ทธ์ธ
- float()ํจ์ ; ์ ์ โ ์ค์โ ์๋ฃํ ๋ณํ ์, ์ ํ ๋ค๋ฅธ ์๊ฐ ๋จ !โ ์ ์ํ ๋๋์ ๊ฒฐ๊ณผ๋ ์ค์ํ( * ํ์ด์ฌ ์ธํฐํ๋ฆฌํฐ์ ํน์ง, ์ค์ค๋ก ์ค์ํ์ผ๋ก ๋ณํ)
- #์ค์ํ a = 10 b = 3 print(a / b) #3.33333..
- #์ ์ํ a = 10 print(a) #10 #์ค์ํ a = float(10) print(a) #10.0
- int()ํจ์ ; ์ค์ โ ์ ์โ ์ ์ํ ๋ณํ์ผ๋ก ์์์ ์ดํ ๋ด๋ฆผ ๋ฐ์( * ๊ธฐ์กด์ ์ํ๊ณผ ์ฐจ์ด์ )
- #์ค์ํ์ ์ ์ํ์ผ๋ก ๋ณํ a = int(10.7) b = int(10.3) #์ถ๋ ฅ๊ฐ ํ์ธ print(a + b) #20 print(a) #10 print(b) #10
์ซ์ํ๊ณผ ๋ฌธ์ํ ๊ฐ์ ๋ณํ
- ์๋ฐฉํฅ ๋ณํ ๊ฐ๋ฅ
- ๋ฌธ์ํ โ ์ ์ & ์ค์ํ ๋ณํ ๊ฐ๋ฅ, ์ญ๋ ๊ฐ๋ฅ!
: a ๋ฌธ์ํ์ผ๋ก ์ ์ธ โ float()ํจ์ ํตํด b ์ค์ํ ๊ฐ ํ ๋น โ ๋์ผํ ๊ฐ ์ถ๋ ฅa = '76.3' b = float(a) #๋ฌธ์ํ print(a) #76.3 #์ค์ํ print(b) #76.3 print(a+b) #error ๋ฐ์
- but a+b ? โ ์ซ์ํ๊ณผ ๋ฌธ์ํ์ ๊ธฐ๋ณธ ์ฐ์ฐ ๋ถ๊ฐ , ์๋ฃํ ํต์ผ ํ์
- Traceback (most recent call last):TypeError: can only concatenate str (nor "float") to str
- File "<stdin>", line 1, in <module>
- str()ํจ์ ; ๋ฌธ์ํ ์๋ ์๋ฃํ โ ๋ฌธ์ํโ ๋ฌธ์ํ ๊ฐ ๋ง์ : ๋ฌธ์์ด ๊ฐ ๋จ์ ์ฐ๊ฒฐ(๋จ์ ๋ถ์ด๊ธฐ)
- #์ค์ํ a = float(a) b = a print(a+b) #152.6 #๋ฌธ์ํ a = str(a) b = str(b) print(a+b) #76.376.3
์๋ฃํ ํ์ธํ๊ธฐ
- ๋ณ์์ ์๋ฃํ ํท๊ฐ๋ฆด ๋!
- type() ํจ์โ ๋ณ๋์ ์ถ๋ ฅํจ์ ์ฌ์ฉํ์ง ์์ ๋
- a = int(10.3) b= float(10.3) c = str(10.3) #์๋ฃํ ์ถ๋ ฅ type(a) #<class 'int'> type(b) #<class 'float'> type(c) #<class 'str'>
#4. ๋ฆฌ์คํธ์ ์ดํด
๋ฆฌ์คํธ๊ฐ ํ์ํ ์ด์
- ๋ฐฐ์ด (array)
- ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉํ๋ ์๋ฃํ
- ex. ํ์ 100 ๋ช
์ ์ฑ์ ์ฑ์ ํ ๋ โ
๋ณ์ 100 ๊ฐ ํ์ฉ/ ํ ๊ฐ ๋ณ์์ ๋ชจ๋ ํ์ ์ฑ์ ๋ด๊ธฐ !
- ex. ํ์ 100 ๋ช
์ ์ฑ์ ์ฑ์ ํ ๋ โ
- ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉํ๋ ์๋ฃํ
- ํ ๋ณ์์ ๋ชจ๋ ๊ฐ ์ ์ฅ ๋ฐฉ์ , ๋ฐฐ์ด in programming / ๋ฆฌ์คํธ in python
๊ฐ๋
- ํ ๋ณ์์ ์ฌ๋ฌ ๊ฐ ์ ์ฅํ๋ ์๋ฃํ
- ์ํ์ค ์๋ฃํ(sequence type)
- ์ฌ๋ฌ ๋ฐ์ดํฐ ํ ๋ณ์์ ์ ์ฅํ๋ ๊ธฐ๋ฒ
- ์ฌ๋ฌ ์๋ฃ ์์๋๋ก ์ ์ฅ
- ์ ์, ์ค์, ๋ณ์ ๋ฑ ๋ค์ํ ์๋ฃํ ์ ์ฅ ๊ฐ๋ฅ
- #๋ฌธ์ํ,์ ์ํ,์ค์ํ a = [โcolorโ,1,0.2] #์ค์ฒฉ ๋ฆฌ์คํธ color = ['red','blue'] a[0] = color print(a) #[['red','blue'],1,0.2]
- ๋ฆฌ์คํธ ์์ฑ
- ๋ฆฌ์คํธ ๋ช = [๊ฐ, ๊ฐ, ๊ฐ, .. ]
- ๋น ๋ฆฌ์คํธ ์์ฑ
โ ์ค์ ๋ด๊ธด ๊ฐ: ๋ฌธ์ํ์ red, blue, green#๋ฆฌ์คํธ์ ๊ฐ ํ ๋น colors = ['red','blue','green'] #๋ฆฌ์คํธ์ ๊ฐ ํ ๋น - ๊ฐ๋ณ ๋ฐ์ดํฐ colors = 'red' colors = 'blue' colors = 'green' #๋น ๋ฆฌ์คํธ abc =[]
- โ ๋๊ดํธ([]) ์ฌ์ฉ, ์ฝค๋ง(,)๋ก ์์ ๊ตฌ๋ถ
์ธ๋ฑ์ฑ & ์ฌ๋ผ์ด์ฑ
๋ฆฌ์คํธ ๋ค๋ฃจ๊ธฐ ์ํด ๋ฐ๋์ ์ดํดํ ๊ฒ
- ์ธ๋ฑ์ฑ(indexing)
- ์ ์ฅ๋ ๊ฐ์ ์ ๊ทผํ๊ธฐ ์ํด ์๋์ ์ธ ์ฃผ์ ์ฌ์ฉ
- ์ฃผ์ โ ์ฒซ ๋ฒ์งธ ๊ฐ์ด 0์ผ ๊ฒฝ์ฐ, ์ด์ ์ผ๋ง๋ ๋จ์ด์ ธ ์๋์ง
- ์ฃผ์ or ์ธ๋ณ์ค ๊ฐ
colors = ['red','blue','green'] print(colors[0]) #red print(colors[1]) #blue print(colors[2]) #green #colors์ ๊ธธ์ด print(len(colors)) #3
- colors ์ธ๋ฑ์ค

โ 0๋ฒ์งธ๋ถํฐ 0, 1, 2 ์ฃผ์๊ฐ์ผ๋ก ํธ์ถ ๊ฐ๋ฅ
โ len() ํจ์ : length, ๋ฆฌ์คํธ ๊ธธ์ด ๋ฐํ, ๊ฐ์ ๊ฐ์ ๋ฐํ
+ ์ ์ธ๋ฑ์ค๋ 0๋ถํฐ ์์ํ ๊น?
: ๋๋ถ๋ถ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด ์ฃผ์๊ฐ 0๋ถํฐ ์์, ์ด์ง์
- ์ฌ๋ผ์ด์ฑ(slicing)
- ์ธ๋ฑ์ค ์ฌ์ฉ โ ๋ฆฌ์คํธ ๊ฐ ์ค ์ผ๋ถ ์ถ์ถ
cities = ['์์ธโ,โ๋ถ์ฐโ,โ์ธ์ฒโ,โ๋๊ตฌโ,โ๋์ โ,โ๊ด์ฃผโ,โ์ธ์ฐโ,โ์์โ]

- ์ฌ๋ผ์ด์ฑ ๊ธฐ๋ณธ ๋ฌธ๋ฒ
- ๋ฆฌ์คํธ๋ช [์์ ์ธ๋ฑ์ค : ๋ง์ง๋ง ์ธ๋ฑ์ค]
โ ์ฐ๋ฆฌ์ ์์ - ์์ธ ~ ๋๊ตฌ / ์ค์ ์ถ๋ ฅ๊ฐ - ์์ธ ~ ์ธ์ฒ</aside>โ ์ค์ ์ถ๋ ฅ: [์์ ์ธ๋ฑ์ค : ๋ง์ง๋ง ์ธ๋ฑ์ค - 1]cities[0:3] #['์์ธ','๋ถ์ฐ','์ธ์ฒ']
- ์์
#์์ธ๋ถํฐ ๋์ cities[0:5] #['์์ธ','๋ถ์ฐ','์ธ์ฒ','๋๊ตฌ','๋์ '] #์ธ์ฒ๋ถํฐ ๊ด์ฃผ cities[2:6] #๊ด์ฃผ๋ถํฐ ์์ cities[5:] #['๊ด์ฃผ','์ธ์ฐ','์์']
- โ ์ ๋ ฅ: [์์ ์ธ๋ฑ์ค : ๋ง์ง๋ง ์ธ๋ฑ์ค]
- ๐ญ ๋ง์ง๋ง ์ธ๋ฑ์ค - 1๊น์ง ์ถ๋ ฅ in python
- ๋ฆฌ๋ฒ์ค ์ธ๋ฑ์ค
- ๋ง์ง๋ง ๊ฐ๋ถํฐ ์ธ๋ฑ์ค ์์
- ๊ฐ์ฅ ๋ง์ง๋ง ๊ฐ๋ถํฐ -1 ๋ถ์ฌ โ ์ฒซ์งธ ๊ฐ๊น์ง ์ญ์ ๋ถ์ฌ

#๋ฆฌ์คํธ ์ ์ฒด ๊ฐ
cities[-8:] #['์์ธ', ~,'์์']
โ -8๋ถํฐ ์ธ๋ฑ์ค ๋๊น์ง ์ถ๋ ฅ
- ํ์ฉ
- ์ฒ์๋ถํฐ โ [: n] (*์ถ๋ ฅ๋๋ ๋ง์ง๋ง ๊ฐ :(n-1)๋ฒ์งธ)
- ๋๊น์ง โ [n :]
- ์ธ๋ฑ์ค ๋ฒ์ ์ด๊ณผ ์ฌ๋ผ์ด์ฑ
- ์ธ๋ฑ์ค ์์ ๊ฐ, ๋ง์ง๋ง ๊ฐ ๋น์ด ์์ด๋ ์๋
โ ์ธ๋ฑ์ค ๋ฒ์ ์ด๊ณผ or ์ ๋ ฅํ์ง ์์ผ๋ฉด ์๋์ผ๋ก ์ง์ ๋จ#cities ๋ชจ๋ ๊ฐ ๋ฐํ cities[0:9] cities[0:] cities[:] #์ธ๋ณ์ค ๊ฐ ์ด๊ณผ cities[-50:50] #cities ์ ์ฒด ๊ฐ ์ถ๋ ฅ๋จ
- ์ฆ๊ฐ๊ฐ(step)
- ๋ฆฌ์คํธ๋ช [์์ ์ธ๋ฑ์ค: ๋ง์ง๋ง ์ธ๋ฑ์ค: ์ฆ๊ฐ๊ฐ]
#์ ์ฒด ๊ฐ ์ถ๋ ฅ - 2์นธ ๋จ์ cities[::2] #[โ์์ธโ,โ์ธ์ฒโ,โ๋์ โ,โ์ธ์ฐโ] #์ ์ฒด ๊ฐ ์ถ๋ ฅ - 1์นธ ๋จ์ & ์ญ์ cities[::-1] #['์์','์ธ์ฐ',~'์์ธ']
์ฐ์ฐ
- ๋ง์ โ ๋ง์ ์ฐ์ฐ : ๊ฐ ๋ฆฌ์คํธ ํ๋์ ๋ฆฌ์คํธ๋ก ํฉ์ณ์ ธ ์ถ๋ ฅ
- โ ๊ธฐ์กด color1, color2 ์ํฅ ๋ฐ์ง ์์ (*len()์ผ๋ก ํ์ธ)
- color1 = ['red','blue','green'] color2 = ['orange','black','pink'] #๋ ๋ฆฌ์คํธ ํฉ์น๊ธฐ - 1 print(color1 + color2) #['red','blue','green','orange','black','pink'] #๋ ๋ฆฌ์คํธ ํฉ์น๊ธฐ - 2 total_color = color1 + color2 print(total_color) #์์ ๋์ผ #๊ธฐ์กด ๋ฆฌ์คํธ ๋ณํ ํ์ธ len(color1) #3
- ๊ณฑ์
- ๋ฆฌ์คํธ x n โ ๋ฆฌ์คํธ nํ ๋ฐ๋ณต
#2ํ ๋ฐ๋ณต color1 * 2 #['red','blue','green','red','blue','green']
- in ์ฐ์ฐ
- ํน์ ๊ฐ ํฌํจ์ฌ๋ถ ํ์ธ ์ฐ์ฐ
color2 = ['orange','black','pink'] #๋ฌธ์์ด 'blue' ํฌํจ์ฌ๋ถ ํ์ธ 'blue' in color2 #False
์ถ๊ฐ & ์ญ์ & ๊ฐ ๋ณ๊ฒฝ
- ํ ๋์ ๋ณด๊ธฐ

- ์ถ๊ฐ - append() ํจ์
- ๋ฆฌ์คํธ ๋งจ ๋ง์ง๋ง ์๋ก์ด ๊ฐ ์ถ๊ฐ
color = ['red','blue','green'] #'white' ์ถ๊ฐ color.append('white') #ํ์ธ color #['red','blue','green','white']
- ์ง์ ์ ๋ ฅ๋ฐ์ ์ถ๊ฐ
#์ด ๋ฌผ๊ฑด ์ ๋ ฅ๋ฐ๊ธฐ to_get = [] item = input("์ด ๋ฌผ๊ฑด์ ์ ๋ ฅํด์ฃผ์ธ์ ->") to_get.append(item) print(to_get)

- ์ถ๊ฐ - extend() ํจ์
- ๋ง์ ์ฐ์ฐ
- ๊ฐ ์ถ๊ฐ X โ ๊ธฐ์กด ๋ฆฌ์คํธ์ ์๋ก์ด ๋ฆฌ์คํธ ์ถ๊ฐ
color = ['red','blue','green'] color.extend(['black','purple']) color #['red','blue','green','black','purple']
- ์ถ๊ฐ - insert() ํจ์
- append์ ์ฐจ์ด์
- ํน์ ์์น(์ง์ ์์น)์ ๊ฐ ์ถ๊ฐ
โ ๊ธฐ์กด ๊ฐ ์ธ๋ฑ์ค ํ๋์ฉ ๋ฐ๋ฆผcolor = ['red','blue','green'] color.insert(0, 'orange') color #['orange','red','blue','green']
- append์ ์ฐจ์ด์
- ์ ๊ฑฐ - remove() ํจ์
- ํน์ ๊ฐ ์ญ์
- ๊ธฐ๋ณธ๋ฌธ๋ฒ
- remove(โ๊ฐโ)
โ ๋ค์ ๊ฐ๋ค ํ ์นธ์ฉ ์์ผ๋ก ์ด๋color = ['red','blue','green'] color.remove('red') color #['blue','green']
- ์ ๊ฑฐ - del ํจ์
- ๊ธฐ๋ณธ ๋ฌธ๋ฒ
- del ๋ฆฌ์คํธ๋ช [์ธ๋ฑ์ค]
color = ['red','blue','green'] del color[0] color #['blue','green']
- ์ผ๋ฐ์ ์ผ๋ก ๋ณ์ ์์ฒด ์ญ์ ๋ช ๋ น
- but ๋ฆฌ์คํธ ๋ด ์ธ๋ฑ์ค ์ง์ โ remove()ํจ์์ ๋์ผํ ๊ธฐ๋ฅ
- ๊ธฐ๋ณธ ๋ฌธ๋ฒ
- ๊ฐ ๋ณ๊ฒฝ
- ๋ฆฌ์คํธ๋ช [์ธ๋ฑ์ค ๊ฐ] = ๋ฐ์ดํฐ
โ ํน์ ์ธ๋ฑ์ค์ ๊ฐ ๋ณ๊ฒฝํ ๋ ์ธ๋ฑ์ค์ ์๋ก์ด ๊ฐ ํ ๋นcolor = ['red','blue','green'] color[0] = 'orange' color #['orange','blue','green']
- ์ฌํ
- ์ฆ๊ฐ ์ฐ์ฐ
#๊ตญ์ด ์ ์ 3๊ฐ์ ๊ฐ ๋ณํ ์ถ์ด kor_score = [50, 89, 90] print('์์ ์ :',kor_score) kor_score[0] += 29 print('์์ ํ:', kor_score)

- ๊ฐ์์ฐ์ฐ
#๊ตญ์ด ์ ์ 3๊ฐ์ ๊ฐ ๋ณํ
kor_score = [50, 89, 90]
print('์์ ์ :',kor_score)
kor_score[2] -= 10
print('์์ ํ:', kor_score)

๋ค์ํ ๋ช ๋ น์ด
- ์ ๋ ฌ
- ๊ธฐ๋ณธ ๋ฌธ๋ฒ
- ๋ฆฌ์คํธ๋ช .sort()
- ์ค๋ฆ์ฐจ์ ์ ๋ ฌ - ํ๊ธ : ๊ฐ๋๋ค์, ์์ด : ์ํ๋ฒณ์
fruit = ['์ฌ๊ณผ','๋ฐ๋๋','๋ธ๊ธฐ','๊ทค','์ฒญํฌ๋'] fruit.sort() print('์ ๋ ฌ ํ:',fruit)
- ๊ธฐ๋ณธ ๋ฌธ๋ฒ

- ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ - reverse=True
fruit = ['์ฌ๊ณผ','๋ฐ๋๋','๋ธ๊ธฐ','๊ทค','์ฒญํฌ๋']
fruit.sort(reverse=True)
print('์ ๋ ฌ ํ:',fruit)

- ์ต๋๊ฐ , ์ต์๊ฐ, ํฉ
- max() ; ์ต๋๊ฐ / min() ; ์ต์๊ฐ
#๊ตญ์ด ์ ์ 3๊ฐ์ ๊ฐ ๋ณํ ์ถ์ด kor_score = [50, 89, 90] #์ต๋๊ฐ print(max(kor_score)) #90 #์ต์๊ฐ print(min(kor_score)) #50
- sum() ; ํฉ
print(sum(kor_score)) #229
- ์ธ๋ฑ์ค ์ฐพ๊ธฐ
- ๊ธฐ๋ณธ ๋ฌธ๋ฒ
- ๋ฆฌ์คํธ๋ช .index(์ฐพ์ผ๋ ค๋ ๋ฐ์ดํฐ)
- ํด๋น ๊ฐ์ ์ธ๋ฑ์ค ๊ฐ ๋ฐํ
- ๊ธฐ๋ณธ ๋ฌธ๋ฒ
ํจํน & ์ธํจํน
- ๋ฆฌ์คํธ ์ฌ์ฉ๋ฒ
- ์ํ์ค ์๋ฃํ์์ ์ฌ์ฉ๋จ
t = [1,2,3] #ํจํน
a, b, c = t #์ธํจํน
print(t,a,b,c) #[1,2,3]123
- ํจํน : ํ ๋ณ์์ ์ฌ๋ฌ ๋ฐ์ดํฐ ํ ๋น(= ๋ฆฌ์คํธ)
- ์ธํจํน : ํ ๋ณ์ ์ฌ๋ฌ ๋ฐ์ดํฐ ์์ ๋, ๊ฐ ๋ณ์๋ก ๋ฐํ
- ๋ฆฌ์คํธ ๊ฐ ๊ฐ์ = ํ ๋นํ ๋ณ์ ๊ฐ์ (์๋ก ๋ค๋ฅด๋ฉด ์๋ฌ ๋ฐ์!)
2์ฐจ์ ๋ฆฌ์คํธ
- for ๋ฆฌ์คํธ ํจ์จ์ ํ์ฉ, ์ฌ๋ฌ ๊ฐ ๋ฆฌ์คํธ โ ํ ๋ณ์์ ํ ๋น
- ํ๋ ฌ๊ณผ ๊ฐ์ ๊ฐ๋
- ์์ ) ํ์๋ณ ๊ตญ์ด, ์ํ, ์์ด ์ ์ ํ

- ์ฝ๋
- #2์ฐจ์ ๋ฆฌ์คํธ ์์ฑ kor_score = [49, 80, 20, 100, 80] math_score = [43, 60, 85, 30, 90] eng_score = [49, 82, 48, 50, 100] midterm_score = [kor_score, math_score, eng_score]
- ์คํํ๋ฉด

- 2์ฐจ์ ๋ฆฌ์คํธ ์ ๊ทผ
- ๋๊ดํธ 2 ๊ฐ ์ฌ์ฉํ์ฌ ์ธ๋ฑ์ฑ
โ ์ฒซ์งธ [n] : n ํ / ๋์งธ [m] : m ์ด#1ํ 3์ด ๊ฐ ์ถ๋ ฅ print(midterm_score[0][2]) #20
- ์ ๋ ฅ : nํ, m์ด
- ์ค์ ์ถ๋ ฅ: n+1 ํ, m+1 ์ด
- ์ธ๋ฑ์ค์ ์๋์ ์ฃผ์ ํ์ฉํ๋ ํน์ง๋๋ฌธ!
- ์์ 1์ฐจ์ ๋ฆฌ์คํธ ์ธ๋ฑ์ฑ ์ฃผ์๊ฐ๊ณผ ๋์ผํ ํน์ง
'๐ ์คํฐ๋ > ํ์ด์ฌ ์คํฐ๋ ๊ฐ์์๋ฃ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[3ํ/์ด์งํ] 2์ฐจ์ ํ์ด์ฌ ์คํฐ๋ - ์๋ฃํ (0) | 2023.03.15 |
---|---|
[2ํ/๊น๊ฐ๋ฆผ, ์ต๋ค์] 2์ฐจ์ ํ์ด์ฌ ์คํฐ๋ - ์๋ฃํ (2) | 2023.03.15 |
[1ํ/ํ์์] 1์ฐจ์ ํ์ด์ฌ ์คํฐ๋ - ์ ์ถ๋ ฅ (0) | 2023.03.09 |
[4ํ/์ด๋๊ฒฝ] 1์ฐจ์ ํ์ด์ฌ ์คํฐ๋ - ์ ์ถ๋ ฅ (0) | 2023.03.09 |
[2ํ/๊น์ธ์ฐ] 1์ฐจ์ ํ์ด์ฌ ์คํฐ๋ - ์ ์ถ๋ ฅ (0) | 2023.03.09 |