List
๋จ์ผ ๋ณ์์ ์ฌ๋ฌ ํญ๋ชฉ์ ์ ์ฅํ๋ ๋ฐ ์ฌ์ฉ๋๋ค.
List ํญ๋ชฉ์ ์์๊ฐ ์ง์ ๋๊ณ ๋ณ๊ฒฝ ๊ฐ๋ฅํ๋ฉฐ ์ค๋ณต๊ฐ ํ์ฉ
List ์๋ ๋ค์ํ ๋ฐ์ดํฐ ์ ํ์ด ํฌํจ๋ ์ ์๋ค.
1. ํ์
thislist = ["ํผ์นด์ธ", "๋ผ์ด์ธ", "๊ผฌ๋ถ๊ธฐ"]
print(thislist)
2. n๋ฒ์งธ ๊ฐ ๊ฐ์ ธ์ค๊ธฐ
print(thislist[0]) #0๋ฒ ์งธ ๊ฐ ํผ์นด์ธ ๊ฐ์ง๊ณ ์ด
print(thislist[0][0]) #ํผ์นด์ธ์ 0๋ฒ์งธ ๊ฐ ํผ
3. List ๊ธธ์ด
print(len(thislist))
4. List ๋ฐ์ดํฐ ์ ํ
List1 = ["ํผ์นด์ธ", "๋ผ์ด์ธ", "๊ผฌ๋ถ๊ธฐ"]
List2 = [1, 2, 3, 4, 5]
List3 = [True, False, False]
#๋ค์ํ ์ ํ ํฌํจ ๊ฐ๋ฅ
List4 = ["abc", 34, False, 40]
#thislist = ["ํผ์นด์ธ", "๋ผ์ด์ธ", "๊ผฌ๋ถ๊ธฐ"] #ํผ์นด์ธ๊ฐ 0๋ฒ์งธ, ๋ผ์ด์ธ๊ฐ 1๋ฒ์งธ, ๊ผฌ๋ถ๊ธฐ๊ฐ 2๋ฒ์งธ๋ค.
print(thislist[1])
5. ๊ฐ ๋ฐ๊พธ๊ธฐ
thislist[1] = "์ ๋ง๋ณด" #๋ผ์ด์ธ๋ฅผ ์ ๋ง๋ณด๋ก ๋ฐ๊พธ๊ฒ ๋ค.
print(thislist)
6. ํญ๋ชฉ ๋ณ๊ฒฝ 2๊ฐ
thislist = ["ํผ์นด์ธ", "๋ผ์ด์ธ", "๊ผฌ๋ถ๊ธฐ", "ํ์ด๋ฆฌ", "๋ฒํฐํ", "์ผ๋๋"]
thislist[1:3] = ["์ธ๋จน์ด", "๋ฉํ๋ชฝ"]
print(thislist)
7. ๋๋ฒ์งธ ์ธ๋ฒ์งธ ๊ฐ์ ํ๋์ ๊ฐ์ผ๋ก ๋ณ๊ฒฝ
thislist = ["ํผ์นด์ธ", "๋ผ์ด์ธ", "๊ผฌ๋ถ๊ธฐ", "ํ์ด๋ฆฌ", "๋ฒํฐํ", "์ผ๋๋"]
thislist[1:3] = ["์ธ๋จน์ด"]
print(thislist)
8. ํญ๋ชฉ ์ถ๊ฐ
thislist = ["ํผ์นด์ธ", "๋ผ์ด์ธ", "ํ์ด๋ฆฌ"]
thislist.append("๊ผฌ๋ถ๊ธฐ")
print(thislist)
# ํญ๋ชฉ ์ถ๊ฐ - ์ธ๋ฑ์ค ๋ฒํธ๋ก ์ถ๊ฐ
thislist = ["ํผ์นด์ธ", "๋ผ์ด์ธ", "ํ์ด๋ฆฌ"]
thislist.insert(1, "์ ๋ง๋ณด")
print(thislist)
9. ํญ๋ชฉ ์ ๊ฑฐ
#๊ฐ์ผ๋ก ์ ๊ฑฐ
thislist = ["ํผ์นด์ธ", "๋ผ์ด์ธ", "ํ์ด๋ฆฌ"]
thislist.remove("๋ผ์ด์ธ")
print(thislist)
# ํญ๋ชฉ์ ์ง์ ๋ ์ธ๋ฑ์ค๋ก ์ ๊ฑฐ
thislist = ["ํผ์นด์ธ", "๋ผ์ด์ธ", "ํ์ด๋ฆฌ"]
thislist.pop(2)
print(thislist)
# ๋ง์ง๋ง ๊ฐ ์ ๊ฑฐ
thislist = ["ํผ์นด์ธ", "๋ผ์ด์ธ", "ํ์ด๋ฆฌ", "์ ๋ง๋ณด"]
thislist.pop()
print(thislist)
10. ๋ชฉ๋ก ์ญ์
thislist = ["ํผ์นด์ธ", "๋ผ์ด์ธ", "ํ์ด๋ฆฌ"]
thislist.clear()
print(thislist)
11. ํ์ฅ
thislist = ["ํผ์นด์ธ", "๋ผ์ด์ธ", "ํ์ด๋ฆฌ"]
thislist.extend(["๋ฒํฐํ","์ผ๋๋"])
print(thislist)
#๊ฐ์ฒด ์ญ์
#del thislist
#print(thislist) #์ค๋ฅ
#list๋ ์ค์ํ๋ค.
'๐์น ๊ฐ๋ฐ(Web) > ๐ํ์ด์ฌ(Python)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฌธ์์ด(String) (0) | 2023.01.17 |
---|---|
Python Tuple ์ด์ ๋ฆฌ (0) | 2023.01.17 |
Python ๋ด์ฅ ๋ฐ์ดํฐ ์ ํ ์ ๋ฆฌ (0) | 2023.01.16 |
๋ฐ์ง๋ฆ์ ์ ๋ฌํ๋ฉด ์์ ๋์ด๋ฅผ ๋ฐํํ๋ get_area() ํจ์ (0) | 2023.01.16 |
ํ์ด์ฌ ์ค์น/์๋์ฝ๋ค/ํ์ด์ฐธ/๊น ์ค์น/๊นํ๋ธ ๊ฐ์ (0) | 2023.01.13 |