values = [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]

Slicing

print(values[0])   # 10
print(values[-1])  # 19
print(values[-3:]) # [ 17, 18, 19 ] 
print(values[7:])  # [ 17, 18, 19 ]
print(values[:3])  # [ 10, 11, 12 ]
print(values[a:b]) # a <= LIST < b
>>> letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g']

>>> letters[2:5] = ['C', 'D', 'E']   # replace
>>> letters
['a', 'b', 'C', 'D', 'E', 'f', 'g']

>>> letters[2:5] = []    # remove
>>> letters[:] = []      # clear

Operation

list1 = [ 1, 2, 3 ]
list2 = [ 4, 5, 6 ]
list3 = list1 + list2   # [ 1, 2, 3, 4, 5, 6 ]

list1.append(10)   # [ 1, 2, 3, 10 ]
print(len(list1))  # 4

Nested

중첩 가능, 새로운 리스트를 한 리스트의 요소에 포함 가능

>>> a = [ 'a', 'b', 'c' ]
>>> b = [ 1, 2, 3 ]
>>> x = [ a, n ]
>>> x
[['a', 'b', 'c'], [1, 2, 3]]
>>> x[0]
['a', 'b', 'c']
>>> x[0][1]
'b'

'Python' 카테고리의 다른 글

설치된 패키지 목록 저장 및 복원  (0) 2022.08.25
How To Update All Python Packages  (0) 2021.10.13
Anaconda3  (0) 2021.08.16
Fibonacci series  (0) 2021.08.16
Number, String  (0) 2021.08.15

+ Recent posts