[], list() # []
[n for n in range(10)] # [0,1,2,3,4,5,6,7,8,9]
nums = [random.sample(range(20),1)[0] for _ in range(10)] nums # [15, 15, 15, 4, 15, 16, 15, 2, 15, 19]
[n for n in range(30) if n%3 == 0] # [0, 3, 6, 9, 12, 15, 18, 21, 24, 27]
사이즈
len(list) # 3
숫자
nums = [2,5,3]
nums[0] = 100
nums # [100, 5, 3]
문자열
s = list('abc')
s[0] = 'z'
s # ['z', 'b', 'c']
추가
s = list('abc')
list.append('d')
반복문
for emp in empList:
print(emp)
삭제
s = list('abc')
del s[0]
복사
s2 = s[:] # Deep Copy
문자열 -> 숫자
[int(num) for num in ['1','2','3','4','5']
정렬
list_emp = [{'id':1,'name':'Smith'},{'id':2,'name':'Scott'}]
list_emp = sorted(list_emp, key=lambda emp : emp.id)