-
ํ์ด์ฌ | #6 ๋ฆฌ์คํธ์นดํ ๊ณ ๋ฆฌ ์์ 2023. 8. 31. 21:13
๋ฆฌ์คํธ
๋ฆฌ์คํธ๋ ํ๋์ ๋ณ์์ ์ฌ๋ฌ๊ฐ์ ๊ฐ์ ์ง์ด๋ฃ์ ๋ ์ฃผ๋ก ์ฌ์ฉํ๋ค.
ํ์ด์ฌ์์๋ 4๊ฐ์ ๋นํธ์ธ ์ปฌ๋ ์ ๋ฐ์ดํฐ ํ์ ์ ์ ๊ณตํ๊ณ ๋ฆฌ์คํธ๋ ๊ทธ ์ค ํ๋์ด๋ค.
CREAT
names = ["Jane", "Berry", "Thomas"] print(names) #list ์์ฑ์๋ก ๋ฐฐ์ด์ ์์ฑํ ์๋ ์๋ค. age = list((12, 16, 28))
index
์ฒซ๋ฒ์งธ ๊ฐ์ด index 0๋ฒ์ด๋ค.
names = ["Jane", "Berry", "Thomas"] print(names[0]) "Jane" print(names[2]) "Thomas"
length
๋ฐฐ์ด์ ๊ธธ์ด๋ len() ํจ์๋ก ์ถ๋ ฅํ๋ค.
names = ["Jane", "Berry", "Thomas"] print(len(names)) #3 emptyNames = [] print(len(emptyNames)) #0
READ
# ๊ฐ๊ฐ์ ๊ฐ๋ค์ index ๋ฒํธ๋ก ์ ๊ทผํ ์ ์๋ค. names = ["Jane", "Berry", "Thomas"] print(names[1]) #Jane #-๋ฅผ ๋ถ์ด๋ฉด ๋ง์ง๋ง ๊ฐ๋ถํฐ ์ฝ๋๋ค. print(names[-1]) #Thomas # index ๋ฒ์๋ฅผ ์ ํด ์ฝ๋๋ค. print(names[0:2]) #Jane, Berry
CHANGE
names = ["Jane", "Berry", "Thomas"] names[0] = "Tom" print(names) #["Tom", "Berry", "Thomas"] #๋ฒ์ ์ ํด์ ๊ฐ ๋ฐ๊พธ๊ธฐ names[0:2] = ["Lane", "Jun"] #์๋ก์ด ๊ฐ ์ง์ด๋ฃ๊ธฐ names.insert(1, "changed") #insert(์ง์ด๋ฃ์ index ๋ฒํธ, ๊ฐ)