http://biohackers.net/wiki/PythonAndHangul
capitalize()
첫 문자를 대문자로, 나머지 문자를 소문자로 바꿔준다.
1 |
"PYTHON is powerful".capitalize() |
count(parameter, [start, [end]])
parameter가 몇 번 포함되어 있는지 알려준다.
1 |
"python is powerful".count('p') |
encode([encoding, [error]])
str class는 기본적으로 모두 유니코드이다.
2 |
b'\xea\xbo\x80\xeb\x82\x98\xeb\x8b\xa4' |
endswith(postfix, [start,[end]])
postfix로 문자열이 끝나면 True를 반환하고, 그 외의 경우에는 False를 반환
1 |
"python.py".endswith('.py') |
postfix에는 tuple로도 사용가능
1 |
"python.py".endswith(('.txt','.py')) |
expandtabs([tabsize])
tab을 공백으로 치환합니다. default tabsize는 8.
1 |
"python\tis\tpowerful".expandtabs() |
3 |
"python\tis\tpowerful".expandtabs(1) |
find(keyword, [start, [end]])
문자열 keyword가 나타나는 첫 번째 인덱스를 반환한다.
1 |
"python is powerful".find('p') |
3 |
"python is powerful".find('pa') |
isalnum()
알파벳과 숫자로 이루어져 있으면 True, 그 이외의 것은 False
join(sequence)
iterate 가능한 입력인 sequence형 변수를 지정된 문자열로 연결하여 반환합니다.
1 |
list = ["python", "is", "powerful"] |
2 |
",".join(str(s) for s in list) |
lstrip([chars])
문자열의 왼쪽을 잘라냅니다.
replace(old, new, [count])
old를 new로 대체한 결과를 반환합니다. count를 입력인자로 준 경우에는 count 만큼의 횟수만 대체한다.
1 |
"python is powerful".replace("p", "P") |
rstrip([chars])
문자열의 오른쪽을 잘라냅니다. chars가 지정되지 않으면 공백문자를 제거
1 |
"python.py".rstrip(".py") |
split([separator, [maxsplit]])
문자열을 separator로 분리한다.
1 |
"python is powerful".split() |
2 |
['python', 'is', 'powerful'] |
startswith(prefix, [start, [end]])
prefix로 문자열이 시작하면 True를 반환하고 그 외의 경우에는 False를 반환한다.
1 |
"python is powerful".startswith('py') |
strip([chars])
문자열의 양쪽 끝을 잘라낸다.