특정 값이 있는지, 없는지 확인
# in
>>> a = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
>>> 30 in a
True
>>> 100 in a
False
# not in
>>> a = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
>>> 100 not in a
True
>>> 30 not in a
False
시퀀스 객체 연결하기
>>> range(0, 10) + range(10, 20) # 에러 발생
# → TypeError: unsupported operand type(s) for +: 'range' and 'range'
# 리스트 또는 튜플로 만들어 연결하면 해결됨
>>> list(range(0, 10)) + list(range(10, 20))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
>>> tuple(range(0, 10)) + tuple(range(10, 20))
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19)
시퀀스 객체 반복하기
# * 연산자는 시퀀스 객체를 특정 횟수만큼 반복하여 새 시퀀스 객체를 만듬
# 시퀀스객체 * 정수
# 정수 * 시퀀스객체
>>> [0, 10, 20, 30] * 3
[0, 10, 20, 30, 0, 10, 20, 30, 0, 10, 20, 30]
# 위와 동일하게 range는 반복할 수 없음
>>> range(0, 5, 2) * 3
# → TypeError: unsupported operand type(s) for *: 'range' and 'int'
# 그래서 리스트 또는 튜플로 만듬
>>> list(range(0, 5, 2)) * 3
[0, 2, 4, 0, 2, 4, 0, 2, 4]
>>> tuple(range(0, 5, 2)) * 3
(0, 2, 4, 0, 2, 4, 0, 2, 4)
# 문자열은 * 연산자로 반복할 수 있음
>>> 'Hello, ' * 3
'Hello, Hello, Hello, '