파이썬 목록 count() 메서드
예시
목록 에 "cherry" 값이 나타나는 횟수를 반환합니다 fruits
.
fruits = ['apple', 'banana', 'cherry']
x = fruits.count("cherry")
정의 및 사용
이 count()
메서드는 지정된 값을 가진 요소의 수를 반환합니다.
통사론
list.count(value)
매개변수 값
Parameter | Description |
---|---|
value | Required. Any type (string, number, list, tuple, etc.). The value to search for. |
더 많은 예
예시
값 9가 목록에 나타나는 횟수를 반환합니다.
points = [1, 4, 2, 9, 7, 8, 9, 3, 1]
x = points.count(9)