본문 바로가기
Develop/Python

[자료구조] [ Python ] 리스트 List 사용법

by 은세라 2021. 8. 2.

1. 정의

문자열

2. 선언

list = [ ]

#길이가 정해진 리스트 선언
list = [0 for i in range(n)]

#0으로 초기화 된 2차원 배열
matrix = [[o for col in range(m)] for row in range(n)] # m x n matrix

3. 기본 매소드

#Slicing
list[start : end : term]

#길이구하기
len(list)

#삭제하기
del list[idx]

#요소 추가
list.append(x)
list.insert(idx, x) # idx번째에 x를
list += [x, y] #확장extend

#정렬
list.sort()
list_new = sorted(list)

#마지막요소 반환
list.pop()

 

 

참고 : https://jobc.tistory.com/141

 

[Python] 길이가 정해진 리스트 만들기

파이썬에서 리스트를 생성할 때는 그저 아래와 같이 작성하면 쉽게 리스트가 생성이 된다. list = [] 리스트 길이를 지정하고 0으로 초기화 하고 싶다면 다음과 같이 작성하면 된다. list = [0 for i in

jobc.tistory.com

참고2 : https://www.geeksforgeeks.org/python-list-slicing/

 

Python List Slicing - GeeksforGeeks

A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

www.geeksforgeeks.org

참고3 : https://wikidocs.net/14#_4

 

위키독스

온라인 책을 제작 공유하는 플랫폼 서비스

wikidocs.net

댓글