Python‎ > ‎operator‎ > ‎

operator.countOf()

http://www.adilwaseem.com/

Return
Return the number of times b occurs in a.

Syntax
operator.countOf(a,b)-> number of time a occur in b.

Parameters
String & Number

Import module
Importing module is required in the Shell window and the Editor window.

Examples
Example of syntax is:
 >>> x=(1,2,3,4)
>>> y=(2)
>>> operator.countOf(x,y)
1
>>> x={1,2,3,4,5}
>>> operator.countOf(x,2)
1

Applying method in list contains string items.
 >>> 
>>> x=["Python", "Research", "Centre"]
>>> operator.countOf(x, "Python")
1

Limitation
Don't take keyword arguments.
 >>> x=[1,2,3,4,5,6]
>>> operator.countOf(y=[1],x=[1,2,3,4,5,6])
Traceback (most recent call last):
File "<pyshell#96>", line 1, in <module>
operator.countOf(y=[1],x=[1,2,3,4,5,6])
TypeError: countOf() takes no keyword arguments

Comments