a = [10, 20, 30]
a.append(500)
>>> a = [10, 20, 30, 500]
a = [10, 20, 30]
a.insert(2, 500)
>>> a = [10, 20, 500, 30]
a = [10, 20, 30]
print(a.pop(1))
>>> 20
a = [10, 20, 30]
del a[1]
>>> a = [10, 30]
a = [10, 20, 30, 20]
a.remove(20)
>>> a = [10, 30, 20]
a = [10, 20, 30, 15, 20, 40]
print(a.index(20))
>>> 1
a = [10, 20, 30, 15, 20, 40]
print(a.count(20))
>>> 2
a = [10, 20, 30, 15, 20, 40]
a.reverse()
>>> a = [40, 20, 15, 30, 20, 10]
a = [10, 20, 30, 15, 20, 40]
a.sort()
>>> a = [10, 15, 20, 20, 30, 40]
a = [10, 20, 30, 15, 20, 40]
b = sorted(a)
>>> b = [10, 15, 20, 20, 30, 40]
a = [10, 20, 30]
a.clear()
>>> a = []
a = (38, 21, 53, 62, 19, 53)
print(a.index(53))
>>> 2
a = (10, 20, 30, 15, 20, 40)
print(a.count(20))
>>> 2
a = 'Hello, world!'
a = a.replace('Hel', '')
print(a)
>>> lo, world!
table = str.maketrans('aeiou', '12345')
print('apple'.translate(table))
>>> 1ppl2
- 구분자 문자열과 문자열 리스트 연결하기 or 리스트→문자열 변경
a = ' '.join(['apple', 'pear', 'grape', 'pineapple'])
print(a)
>>> apple pear grape pineapple
a = 'apple pear grape pineapple orange'.split()
print(a)
>>> ['apple', 'pear', 'grape', 'pineapple', 'orange']
a = 'apple pineapple'.index('pl')
print(a)
>>>2
a = 'apple pineapple'.count('pl')
print(a)
>>> 2
x = {'a': 10, 'b': 20, 'c': 30, 'd': 40}
x.update(a=90)
print(x)
>>> {'a': 90, 'b': 20, 'c': 30, 'd': 40}
x = {'a': 10, 'b': 20, 'c': 30, 'd': 40}
print(x.pop('a'))
>>> 10
x = {'a': 10, 'b': 20, 'c': 30, 'd': 40}
del x['a']
print(x)
>>> {'b': 20, 'c': 30, 'd': 40}
x = {'a': 1, 'b': 20, 'c': 30, 'd': 40}
print(x.get('a'))
>>> 10
keys = ['a', 'b', 'c', 'd']
x = dict.fromkeys(keys, 100)
print(x)
>>> {'a': 100, 'b': 100, 'c': 100, 'd': 100
- 반복문으로 딕셔너리의 키-값 쌍을 모두 출력하기
x = {'a': 10, 'b': 20, 'c': 30, 'd': 40}
for key, value in x.items():
print(key, value)
>>> a 10
b 20
c 30
d 40
a = set('apple')
print(a)
>>> {'a', 'l', 'e', 'p'}
a = {1, 2, 3, 4}
a.add(5)
print(a)
>>> {1, 2, 3, 4, 5}
a = {1, 2, 3, 4}
a.remove(3)
print(a)
>>> {1, 2, 4}
a = {1, 2, 3, 4}
a.discard(2)
print(a)
>>> {1, 4, 5}