Python‎ > ‎tuple‎ > ‎

tuple.count()

http://www.adilwaseem.com/

Definition
Return with the position of tuple item in tuple.

Syntax
tuple.count(x)->integer

Parameters
x=position of item in the tuple
if no value raise value error.

Example
The return is:
 tuple1=(44,22,13,22,45,555,32,33)
y=tuple1.count(22)
print("The number of the items in the tuple1 is: ", y)

>>> 
The number of the items in the tuple1 is: 2
>>>

str.partition==tuple
The str.partition converted the string into tuple.
 >>> "Python Lake".partition("Lake")
('Python ', 'Lake', '')
>>> type("Python Lake".partition("Lake"))
<class 'tuple'>
>>> z="Python Lake".partition("Lake")
>>> z.count("Lake")
1


count(str.rpartition())
The returns are following:
 >>> "Python Lake".rpartition("h")
('Pyt', 'h', 'on Lake')
>>> type("Python Lake".rpartition("h"))
<class 'tuple'>
>>> z="Python Lake".rpartition("h")
>>> z=('Pyt', 'h', 'on Lake')
>>> z=('Pyt', 'h', 'on Lake')
>>> z.index('h')
1
>>> 'Pyt'+'h'+ 'on Lake'
'Python Lake'
>>> z.count("Lake")
0
>>> z.count('h')
1

Comments