Python

Python Menu

Python

Python String count() - Definition, Syntax, Parameters, Examples

Definition

The count() method returns the number of times a specified value appears in the string.

Syntax

string.count(value, start, end)

Parameters

Parameter Description
value Required. A String. The string to value to search for
start Optional. An Integer. The position to start the search. Default is 0
end Optional. An Integer. The position to end the search. Default is the end of the string

Examples:

myStr = "I love Math and Science, Math is one of my favorite subjects." result = myStr.count("Math") print(result) # searching from position 5 to 27 result2 = myStr.count("Math", 5, 27) print(result2)

Introduction

Python Basics

Python Advance

Data Science Python Tutorials

Python Functions and Methods