Python Tuple count() MethodPython count() method counts the occurrence of an element in the tuple. It returns the occurrence of the the element passed during call. It required a parameter which is to be counted. It returns error if the parameter is missing. If the item is missing in the tuple, it simply returns 0. Signature and examples of this method are given below. SignatureParameterselem: Element to be counted. ReturnIt returns occurrence of the element. Let?s see some examples of count() method to understand it?s functionality. Python Tuple count() Method Example 1Let?s first see an example to count the occurrence of 2 in the tuple. Output: (2, 4, 6, 8, 10) Occurences: 1 (2, 4, 6, 8, 10, 2) Occurences: 2 Python Tuple count() Method Example 2If the count element is missing, it simply returns 0 except any errror or exception. See the below. Example. Output: (2, 4, 6, 8, 10) Occurences: 0 Python Tuple count() Method Example 3Elements can be of any type (special chars, spaces etc) and the count() method works for all. See an example which returns occurrences of an empty string. Output: (12, 4, 6, 8, 10, '', '', '', '@', '@', '$', '@') Occurences: 3 Occurences: 3 Next TopicVariable length arguments in python |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India