여러 자료형을 담을 수 있고, 여러 요소(element)를 하나의 변수로 사용할 수 있음
[] 대괄호를 이용
list = [1, 1.25, 1, 'word', [1, 2, [3, 4]]]
list[4[2]]❌ 인덱스를 n차원 배열처럼 작성 list[4][2]⭕list[:2]print(list[0]) ➡ 1
#리스트 내 리스트 요소 출력
print(list[4][2]) ➡ [3, 4]
print(list[4][2][0]) ➡ 3
#리스트 내 문자열의 문자 출력
print(list[3][0]) ➡ w
#슬라이싱
print(list[2:4]) ➡ [1, 'word']
#인덱싱과 슬라이드 중첩사용
print(list[3][2][0][1]) ➡ 실
print(list[3][2][0][:2]) ➡ 매실
+ * : 더하기, 반복list1 = [1, 2, 3]
list2 = [4, 5, 6]
#덧셈
print(list1 + list2) ➡ [1, 2, 3, 4, 5, 6]
#반복
list3 = list1*2 + list2
print(list3) ➡ [1, 2, 3, 1, 2, 3, 4, 5, 6]
#길이
print(len(list3)) ➡ 9
💡 리스트의 특징
del 키워드를 사용하여 요소를 삭제할 수 있음list = [1, 5.2, 2*3, ['커피', '물', ['매실차', '유자차']]]
#변경
list[3] = "변경"
print(list) = [1, 5.2, 6, '변경']
#삭제
del list[3]
print(list) = [1, 5.2, 6]
[리스트]를 입력하여 리스트를 요소로 추가 가능[리스트]를 입력하여 리스트에 요소로 추가 가능💡 append()와 extend()의 차이
extend는+덧셈 연산과 같은 작용을 함
➡ append는 요소로 더해주기 / extend는 리스트를 확장하기list = [1, 2, 3, 4] list.append([5, 6]) ➡ [1, 2, 3, 4, [5, 6]] list.extend([5, 6]) ➡ [1, 2, 3, 4, 5, 6]
list = [4, 3, 5, 2, 6, 1, 6]
list.sort() ➡ [1, 2, 3, 4, 5, 6, 6]
list.reverse() ➡ [6, 6, 5, 4, 3, 2, 1]
list.append(8) ➡ [6, 6, 5, 4, 3, 2, 1, 8]
list.append([77, 99]) ➡ [6, 6, 5, 4, 3, 2, 1, [77, 99]]
list.extend([9, 10]) ➡ [6, 6, 5, 4, 3, 2, 1, 9, 10]
list.insert(2, "삽입") ➡ [6, 6, 5, "삽입", 4, 3, 2, 1]
list.remove(5) ➡ [6, 6, 4, 3, 2, 1]
list.count(6) ➡ 2
#pop
last = list.pop()
print(last) ➡ 1
print(list) ➡ [6, 5, 4, 3, 2]
mid = list.pop(2)
print(mid) ➡ 4
print(list) ➡ [6, 5, 3, 2, 1]