Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- nan
- list
- DataAccess
- 최솟값
- 최댓값
- sklearn
- string
- count()
- 분류 결과표
- elbow method
- len()
- hierarchical_clustering
- pandas
- append()
- insert()
- del
- 덴드로그램
- analizer
- DataFrame
- wcss
- function
- Dictionary
- numpy
- Machine Learning
- 반복문
- matplotlib
- data
- dendrogram
- Python
- IN
Archives
- Today
- Total
개발공부
[Python] String len(), find(), rfind() 본문
문자열의 길이
- len() 함수를 사용하여 몇개의 문자로 되어있는지 알 수 있다.
>>> letters = 'abcdefghijklmnopqrstuvwxyz'
>>> len(letters)
26
문자열 위치 찾기
- find() - 찾고자 하는 문자열이 존재하는 곳의 첫번째 오프셋을 알려준다.
- rfind() - 함수는, 찾고자 하는 문자열이 있는 마지막 오프셋을 알려준다.
poem이라는 문자열이 있다.

'year'이라는 단어의 위치찾기
(찾는 단어 첫글자의 인덱스 반환)
find('year')는 처음 find가 발견된 곳의 'f' 의 오프셋을 반환
rfind('year')는 마지막 find가 발견된 곳의 'f'의 오프셋을 반환
>>> poem.find('year')
162
>>> poem.rfind('year')
170
만일 찾는 단어가 없을시 -1 반환
>>> poem.find('banana')
-1
'Python > Basic' 카테고리의 다른 글
| [Python] List 특징, 생성, 오프셋으로 값 얻기 (0) | 2022.04.20 |
|---|---|
| [Python] String count(), in, startswith() (0) | 2022.04.20 |
| [Python] String 변경, replace() (0) | 2022.04.20 |
| [Python]String +연산자, upper(), lower(), title(), spit() (0) | 2022.04.20 |
| [Python] String 특징, 생성, Slicing(슬라이싱) (0) | 2022.04.20 |