# [TIL]list, tuple

newjinnyยท2021๋ 10์ 15์ผ
0

๋ชฉ๋ก ๋ณด๊ธฐ
4/4

# 3. list

## 3-1 index๋ก ์ ๊ทผ, ์์ 

#index ์ฌ์ฉํ์ฌ ์ ๊ทผ
numbers = [50,60,70]
print(numbers[0])#50
print(data = numbers[2]) #70

#index ์ฌ์ฉํ์ฌ ์์ 
our_list = [50,40,30]
our_list[0] = 15
print(our_list) #[15,40,30]

#๋ค์ฐจ์ ๋ฆฌ์คํธ์ ์ ๊ทผํ๊ธฐ
any_list = [
[1,2,3],
[4,5,6],
[7,8,9],
[[10,11,12], 13, 14]
]
any_list[3] # [[10,11,12], 13, 14]
any_list[3][0] # [10,11,12]
any_list[3][0][1] # 11



## 3-2 ์ถ๊ฐ, ์ ๊ฑฐ

#์ถ๊ฐ
arr = [1,2,3]
arr.append(4)
print(arr) #[1,2,3,4]

#์ ๊ฑฐ
three = [1, 4, 6]
remove_one = three.pop()
print(remove_one) #6
print(three) #[1,4]


# 4. tuple

Tuple์ ์ผ๋ฐ์ ์ผ๋ก 2๊ฐ์์ 5๊ฐ ์ฌ์ด์ ์์๋ค์ ์ ์ฅํ ๋ ์ฌ์ฉ๋๋ฉฐ, ํน์  ๋ฐ์ดํฐ๋ฅผ ad hoc(์ฆ์์ ์ผ๋ก) ํ๊ฒ ํํํ๊ณ  ์ถ์๋ ์ฌ์ฉํ๋ค.

my_list = [1, 2, 3, 4, 5, 6]
a = tuple(my_list[0:2])
b = tuple(my_list[2:4])
c = tuple(my_list[4:6])

tuple_abc = [a,b,c] #[(1,2), (3, 4), (5,6)]

## ๐ list ์ tuple ์ฐจ์ด

• list๋ ์์ ์ด ๊ฐ๋ฅํ๋ค.
• tuple์ ์์ ์ด ๋ถ๊ฐ๋ฅํ๋ค.
I Love Pizza, ๋๋ง์ ํ ํ์ผ๋ก ํ์กฐ๊ฐ์ฉ ๋ง์ถฐ๊ฐ๋ ์ค