- 따옴표 동일함 (like js)
'python' == "python"
- 슬라이싱
s = 'python'
# index가 0부터 시작
s[0] = 'p'
s[1] = 'y'
s[-1] = 'n'
s[-2] = 'o'
s[0:2] = 'py'
s[:2] = 'py'
s = 'hello, world'
s.split(',') # ['hello', ' world']
list(map(strip, s.split(',')))
- in
s = 'python'
if 'y' in s:
print('hi')
print('bye')
- 역순
s = 'python'
s[시작점:끝점:step]
s[::-1] # -1, -2, -3, ...
L = [1, 2, 3, 4]
L_new = L[::-1] # [4, 3, 2, 1], L을 수정하지 않은채로 역순값을 만들 수 있음
for i in range(len(L) - 1, -1, -1):
print(L[i])
print(*L[::-1])
- 제거
s = 'pythonp'
s.replace('p','') # ython
s.replace('p','',1) #yhonp