Programming/Python
1-1 리스트(list)
midnightcoder
2022. 8. 2. 14:17
중첩리스트
>>> a = [[1,2,3],[4,5,6],[7,8,9]]
>>> a[0]
[1, 2, 3]
>>> a[0][1]
2
리스트내에 문자열이 들어 있는 경우 아래와 같이 출력 가능
>>> a =["문자열"]
>>> a[0]
'문자열'
>>> a[0][0]
'문'
발생하는 오류 IndexError : 리스트의 범위를 넘어가면, IndexError 발생 (단, 슬라이싱에서는 발생 안함)
>>> a =[1,2,3,4,5]
>>> a[10]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
in 연산자
리스트안에 해당 요소가 있으면 True, 없으면 False 출력
>>> 1 in [1,2,3]
True
>>> 5 in [1,2,3]
False