문자열!! 문자 여러개가 연속적으로 이어져 있다고 생각. 리스트와 상당히 비슷하다.
# 당연히 변수에 할당해서 사용 가능하고~
>>> 'hello world'. replace('world, python)
>>> 'hello python'
something = str.maketrans('macbook', '1234567')
imac = 'imac'
translate = imac.translate(something)
print(translate)
i123
예제가 이상하지만..
1) str.maketrans('바꿀문자','새문자')
2) translate()
split(): 공백을 기준으로 문자열을 분리하여 리스트! 로 반환,
split(','): (콤마) 기준으로 분리되고, 당연히 다른것도 들어갈수있겠지? splt(':')
join()<->split() : join()은 split 의 반대되는 함수. 즉, 분리한걸 다시 합칠수도 있다. 이름도 join
>>> '-'.join(['macbook','imac','iphone'])
'macbook-imac-iphone'
# 자 이게!! 10칸의 공백을 만들고 왼쪽부터 정렬해라! 즉, 오른쪽 공간은 6칸이 남겠지?
>>> 'imac'.ljust(10)
'imac '
zfill(): 0을 공간에 채우겠다!! ljust 나 rjust 를 쓰면 공간을 만들수 있자나? 거기에 0을 채워 넣는거야.
center(): 가운데 정렬!! (만약 홀수로 떨어지면, 왼쪽에 한칸생김)
>>> 'i want to buy %s' % 'imac'
'i want to buy imac'
>>> 'i want to buy {0} , {1}'.format('imac', 'macbook')
'i want to buy imac , macbook'