Function Details: count_(str)

Description

Returns the number of non-overlapping occurrences of substring sub in string.

Extended Description

count is a Python string method that returns number of non-overlapping occurrences of substring. Optional start and end parameters specify search range. Works with find and index for more complex substring operations. Partners with split for string tokenization and counting elements. Useful in text analysis, character frequency counting, and input validation. Handles empty substrings following specific rules. Essential for text processing and pattern frequency analysis. Returns zero if substring not found.


Function Signature


str.count(sub: str, start: int = None, end: int = None) -> int

Module: str

Class: str

Parameters



Parameter List


  • sub: str
  • start: int
  • end: int

Return


Returns an integer representing the count of non-overlapping occurrences of the substring.


Return Type


int

Output

Explanation

This example shows counting occurrences of a single character and a substring.