colors = ["red", "blue", "green"]
colors[0], colors[1], colors[2]
Output : ('red', 'blue', 'green')
b = colors
b
Output : ('red', 'blue', 'green')
b[1] = "black"
b
Output : ['red', 'blue', 'green']
colors
Output : ['red', 'black', 'green']
์๋ณธ ๋ฐ์ดํฐ๊ฐ ๋ณ๊ฒฝ๋๋ ๋ฌธ์ ๋ฐ์
.copy()
ํ์ฉc = colors.copy()
c
Output : ['red', 'black', 'green']
c[1] = "yellow"
c
Output : ['red', 'yellow', 'green']
colors
Output : ['red', 'black', 'green']
for color in colors:
print(color)
if "white" in colors:
print("True")
movies = ["๋ผ๋ผ๋๋", "๋จผ ํ๋ ์ฐ๋ฆฌ", "์ด๋ฒค์ ์ค", "๋คํฌ๋์ดํธ"]
print(movies)
Output : ['๋ผ๋ผ๋๋', '๋จผ ํ๋ ์ฐ๋ฆฌ', '์ด๋ฒค์ ์ค', '๋คํฌ๋์ดํธ']
movies.append("ํ์ดํ๋")
movies
Output : ['๋ผ๋ผ๋๋', '๋จผ ํ๋ ์ฐ๋ฆฌ', '์ด๋ฒค์ ์ค', '๋คํฌ๋์ดํธ', 'ํ์ดํ๋']
movies.pop()
movies
Output : ['๋ผ๋ผ๋๋', '๋จผ ํ๋ ์ฐ๋ฆฌ', '์ด๋ฒค์ ์ค', '๋คํฌ๋์ดํธ']
movies.extend(["์๋ํ์ผ๋งจ", "์ธ์
์
", "ํฐ๋ฏธ๋ค์ดํฐ"])
movies
Output : ['๋ผ๋ผ๋๋', '๋จผ ํ๋ ์ฐ๋ฆฌ', '์ด๋ฒค์ ์ค', '๋คํฌ๋์ดํธ', '์๋ํ์ผ๋งจ', '์ธ์
์
', 'ํฐ๋ฏธ๋ค์ดํฐ']
movies.remove("์ด๋ฒค์ ์ค")
movies
Output : ['๋ผ๋ผ๋๋', '๋จผ ํ๋ ์ฐ๋ฆฌ', '๋คํฌ๋์ดํธ', '์๋ํ์ผ๋งจ', '์ธ์
์
', 'ํฐ๋ฏธ๋ค์ดํฐ']
movies[3:5]
Output : ['์๋ํ์ผ๋งจ', '์ธ์
์
']
favorite_movies.insert(1, 9.60)
favorite_movies
Output : ['์๋ํ์ผ๋งจ', 9.6, '์ธ์
์
']
favorite_movies.insert(3, 9.50)
favorite_movies
Output : ['์๋ํ์ผ๋งจ', 9.6, '์ธ์
์
', 9.5]
favorite_movies.insert(5, ["๋ ์ค๋๋ฅด๋ ๋์นดํ๋ฆฌ์ค", "์กฐ์ฉํ"])
favorite_movies
Output : ['์๋ํ์ผ๋งจ', 9.6, '์ธ์
์
', 9.5, ['๋ ์ค๋๋ฅด๋ ๋์นดํ๋ฆฌ์ค', '์กฐ์ฉํ']]
isinstance(favorite_movies, list)
Output : True
for each_item in favorite_movies:
if isinstance(each_item, list):
for nested_item in each_item:
print("nested_item", nested_item)
else:
print("each_item", each_item)