Function Details: count_(str)

Description


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


Extended Description


The count() method returns the number of non-overlapping occurrences of a substring in the given string. Optional arguments start and end are interpreted as in slice notation and are used to limit the search to a substring of the string. The search is performed from left to right, and non-overlapping occurrences are counted.


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.